use of org.bukkit.entity.minecart.CommandMinecart in project Bukkit by Bukkit.
the class Command method broadcastCommandMessage.
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
String result = source.getName() + ": " + message;
if (source instanceof BlockCommandSender) {
BlockCommandSender blockCommandSender = (BlockCommandSender) source;
if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
} else if (source instanceof CommandMinecart) {
CommandMinecart commandMinecart = (CommandMinecart) source;
if (commandMinecart.getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
}
Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
String colored = ChatColor.GRAY + "" + ChatColor.ITALIC + "[" + result + ChatColor.GRAY + ChatColor.ITALIC + "]";
if (sendToSource && !(source instanceof ConsoleCommandSender)) {
source.sendMessage(message);
}
for (Permissible user : users) {
if (user instanceof CommandSender) {
CommandSender target = (CommandSender) user;
if (target instanceof ConsoleCommandSender) {
target.sendMessage(result);
} else if (target != source) {
target.sendMessage(colored);
}
}
}
}
use of org.bukkit.entity.minecart.CommandMinecart in project CommandHelper by EngineHub.
the class CommandHelperPlugin method onCommand.
/**
* Called when a command registered by this plugin is received.
*
* @param sender
* @param cmd
* @param commandLabel
* @param args
* @return
*/
@Override
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
String cmdName = cmd.getName().toLowerCase();
if ((sender.isOp() || (sender instanceof Player && (sender.hasPermission("commandhelper.reloadaliases") || sender.hasPermission("ch.reloadaliases")))) && (cmdName.equals("reloadaliases") || cmdName.equals("reloadalias") || cmdName.equals("recompile"))) {
MCPlayer player = null;
if (sender instanceof Player) {
player = new BukkitMCPlayer((Player) sender);
}
ac.reload(player, args, false);
return true;
} else if (cmdName.equalsIgnoreCase("commandhelper")) {
return args.length >= 1 && args[0].equalsIgnoreCase("null");
} else if (cmdName.equals("runalias")) {
// Hardcoded alias rebroadcast
if (args.length == 0) {
return false;
}
String command = StringUtils.Join(args, " ");
if (sender instanceof Player) {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent((Player) sender, command);
playerListener.onPlayerCommandPreprocess(pcpe);
} else if (sender instanceof ConsoleCommandSender || sender instanceof BlockCommandSender || sender instanceof CommandMinecart) {
// event handler that would get them if they would not have started with "/runalias".
if (command.startsWith("/")) {
command = command.substring(1);
}
ServerCommandEvent sce = new ServerCommandEvent(sender, command);
serverListener.onServerCommand(sce);
}
return true;
} else if (cmdName.equalsIgnoreCase("interpreter-on")) {
if (sender instanceof ConsoleCommandSender) {
int interpreterTimeout = Prefs.InterpreterTimeout();
if (interpreterTimeout != 0) {
interpreterUnlockedUntil = (interpreterTimeout * 60 * 1000) + System.currentTimeMillis();
sender.sendMessage("Interpreter mode unlocked for " + interpreterTimeout + " minute" + (interpreterTimeout == 1 ? "" : "s"));
}
} else {
sender.sendMessage("This command can only be run from console.");
}
return true;
} else if (sender instanceof Player && cmdName.equalsIgnoreCase("interpreter")) {
if (!sender.hasPermission("commandhelper.interpreter")) {
sender.sendMessage(MCChatColor.RED + "You do not have permission to run that command");
} else if (!Prefs.EnableInterpreter()) {
sender.sendMessage(MCChatColor.RED + "The interpreter is currently disabled." + " Check your preferences file.");
} else if (Prefs.InterpreterTimeout() != 0 && interpreterUnlockedUntil < System.currentTimeMillis()) {
sender.sendMessage(MCChatColor.RED + "Interpreter mode is currently locked. Run \"interpreter-on\"" + " console to unlock it. If you want to turn this off entirely, set the interpreter-timeout" + " option to 0 in " + CommandHelperFileLocations.getDefault().getPreferencesFile().getName());
} else {
interpreterListener.startInterpret(sender.getName());
sender.sendMessage(MCChatColor.YELLOW + "You are now in interpreter mode. Type a dash (-) on a" + " line by itself to exit, and >>> to enter multiline mode.");
}
return true;
} else {
MCCommandSender mcsender = BukkitConvertor.BukkitGetCorrectSender(sender);
MCCommand mccmd = new BukkitMCCommand(cmd);
return mccmd.handleCustomCommand(mcsender, commandLabel, args);
}
}
use of org.bukkit.entity.minecart.CommandMinecart in project CommandHelper by EngineHub.
the class CommandHelperServerListener method onServerCommand.
@EventHandler(priority = EventPriority.LOWEST)
public void onServerCommand(ServerCommandEvent event) {
// Select the proper CommandSender wrapper.
MCCommandSender sender;
if (event.getSender() instanceof ConsoleCommandSender) {
// Console.
sender = new BukkitMCConsoleCommandSender((ConsoleCommandSender) event.getSender());
} else if (event.getSender() instanceof BlockCommandSender) {
// Commandblock blocks.
sender = new BukkitMCBlockCommandSender((BlockCommandSender) event.getSender());
} else if (event.getSender() instanceof CommandMinecart) {
// Commandblock minecarts.
sender = new BukkitMCCommandMinecart((CommandMinecart) event.getSender());
} else {
// other CommandSenders.
sender = new BukkitMCCommandSender(event.getSender());
}
BukkitMiscEvents.BukkitMCServerCommandEvent cce = new BukkitMiscEvents.BukkitMCServerCommandEvent(event, sender);
EventUtils.TriggerListener(Driver.SERVER_COMMAND, "server_command", cce);
try {
if (event.isCancelled()) {
return;
}
} catch (NoSuchMethodError ex) {
// not cancellable before 1.8.8
}
boolean match = false;
try {
match = Static.getAliasCore().alias("/" + event.getCommand(), sender);
} catch (InternalException e) {
Static.getLogger().log(Level.SEVERE, e.getMessage());
} catch (ConfigRuntimeException e) {
Static.getLogger().log(Level.WARNING, e.getMessage());
} catch (Throwable e) {
sender.sendMessage(MCChatColor.RED + "Command failed with following reason: " + e.getMessage());
// Obviously the command is registered, but it somehow failed. Cancel the event.
e.printStackTrace();
return;
}
// commandhelper null, which just returns true.
if (match) {
event.setCommand("commandhelper null");
}
}
use of org.bukkit.entity.minecart.CommandMinecart in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method execute.
@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
if (!testPermission(commandSender)) {
return true;
}
Map<String, ObjectTag> context = new HashMap<>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(ArgumentHelper.buildArgs(raw_args));
context.put("args", new ListTag(args, true));
context.put("raw_args", new ElementTag(raw_args, true));
context.put("alias", new ElementTag(commandLabel, true));
PlayerTag player = null;
NPCTag npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (EntityTag.isCitizensNPC(pl)) {
npc = NPCTag.fromEntity(pl);
} else {
player = PlayerTag.mirrorBukkitPlayer(pl);
}
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("player"));
} else {
if (commandSender instanceof BlockCommandSender) {
context.put("command_block_location", new LocationTag(((BlockCommandSender) commandSender).getBlock().getLocation()));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_block"));
} else if (commandSender instanceof CommandMinecart) {
context.put("command_minecart", new EntityTag((CommandMinecart) commandSender));
context.put("server", new ElementTag(false));
context.put("source_type", new ElementTag("command_minecart"));
} else {
context.put("server", new ElementTag(true));
context.put("source_type", new ElementTag("server"));
}
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null) {
npc = new NPCTag(citizen);
}
}
script.runCommandScript(player, npc, context);
return true;
}
use of org.bukkit.entity.minecart.CommandMinecart in project MyMaid2 by jaoafa.
the class Cmd_jao method onCommand.
@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if (args.length >= 1 && args[0].equalsIgnoreCase("help")) {
SendUsageMessage(sender, cmd);
return true;
}
if (args.length == 1) {
OfflinePlayer offplayer = Bukkit.getOfflinePlayer(args[0]);
try {
Pointjao Pjao = new Pointjao(offplayer);
int now = Pjao.get();
SendMessage(sender, cmd, "現在" + offplayer.getName() + "が所持しているポイント数は" + now + "ポイントです。");
return true;
} catch (UnsupportedOperationException e) {
SendMessage(sender, cmd, "jaoポイントデータが存在しません。");
return true;
} catch (NullPointerException e) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
SendMessage(sender, cmd, "操作に失敗しました。");
SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
return true;
}
} else if (args.length >= 4) {
// /jao use player point reason
if (args[0].equalsIgnoreCase("add")) {
// /jao add player point reason
OfflinePlayer offplayer = Bukkit.getOfflinePlayer(args[1]);
if (offplayer == null) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
}
int point;
try {
point = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
SendMessage(sender, cmd, "ポイントには数値を指定してください。");
return true;
}
if (point <= 0) {
SendMessage(sender, cmd, "ポイントは1以上を指定してください。");
return true;
}
String reason = "";
int c = 3;
while (args.length > c) {
reason += args[c];
if (args.length != (c + 1)) {
reason += " ";
}
c++;
}
if (sender instanceof Player) {
reason += " (Player: " + sender.getName() + ")";
} else if (sender instanceof BlockCommandSender) {
BlockCommandSender bcs = (BlockCommandSender) sender;
Block block = bcs.getBlock();
reason += " (CmdBlock: " + block.getX() + " " + block.getY() + " " + block.getZ() + ")";
} else if (sender instanceof CommandMinecart) {
CommandMinecart cm = (CommandMinecart) sender;
Location loc = cm.getLocation();
reason += " (CmdCart: " + loc.getX() + " " + loc.getY() + " " + loc.getZ() + ")";
} else if (sender instanceof RemoteConsoleCommandSender) {
reason += " (Rcon)";
} else if (sender instanceof ConsoleCommandSender) {
reason += " (Console)";
} else if (sender instanceof ProxiedCommandSender) {
ProxiedCommandSender pcs = (ProxiedCommandSender) sender;
// コマンドの呼び出しに使用されているCommandSenderを返します。(コマンド実行させられているCommandSender?)
CommandSender Callee_sender = pcs.getCallee();
// このプロキシされたコマンドをトリガしたCommandSenderを返します。(executeコマンドを実行したCommandSender?)
CommandSender Caller_sender = pcs.getCaller();
reason += " (Execute: " + Callee_sender.getName() + " [" + Callee_sender + "] => " + Caller_sender.getName() + " [" + Caller_sender + "])";
} else {
reason += " (実行元特定不能: " + sender.getName() + "|" + sender.toString() + ")";
}
try {
Pointjao Pjao = new Pointjao(offplayer);
boolean bool = Pjao.add(point, reason);
if (bool) {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」に" + point + "ポイントを追加しました。");
} else {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」に" + point + "ポイントを追加できませんでした。");
}
return true;
} catch (UnsupportedOperationException e) {
SendMessage(sender, cmd, "jaoポイントデータが存在しません。");
return true;
} catch (NullPointerException e) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
SendMessage(sender, cmd, "操作に失敗しました。");
SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
return true;
}
} else if (args[0].equalsIgnoreCase("use")) {
// /jao use player point reason
OfflinePlayer offplayer = Bukkit.getOfflinePlayer(args[1]);
if (offplayer == null) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
}
int point;
try {
point = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
SendMessage(sender, cmd, "ポイントには数値を指定してください。");
return true;
}
if (point <= 0) {
SendMessage(sender, cmd, "ポイントは1以上を指定してください。");
return true;
}
String reason = "";
int c = 3;
while (args.length > c) {
reason += args[c];
if (args.length != (c + 1)) {
reason += " ";
}
c++;
}
if (sender instanceof Player) {
reason += " (Player: " + sender.getName() + ")";
} else if (sender instanceof BlockCommandSender) {
BlockCommandSender bcs = (BlockCommandSender) sender;
Block block = bcs.getBlock();
reason += " (CmdBlock: " + block.getX() + " " + block.getY() + " " + block.getZ() + ")";
} else if (sender instanceof CommandMinecart) {
CommandMinecart cm = (CommandMinecart) sender;
Location loc = cm.getLocation();
reason += " (CmdCart: " + loc.getX() + " " + loc.getY() + " " + loc.getZ() + ")";
} else if (sender instanceof RemoteConsoleCommandSender) {
reason += " (Rcon)";
} else if (sender instanceof ConsoleCommandSender) {
reason += " (Console)";
} else if (sender instanceof ProxiedCommandSender) {
ProxiedCommandSender pcs = (ProxiedCommandSender) sender;
// コマンドの呼び出しに使用されているCommandSenderを返します。(コマンド実行させられているCommandSender?)
CommandSender Callee_sender = pcs.getCallee();
// このプロキシされたコマンドをトリガしたCommandSenderを返します。(executeコマンドを実行したCommandSender?)
CommandSender Caller_sender = pcs.getCaller();
reason += " (Execute: " + Callee_sender.getName() + " [" + Callee_sender + "] => " + Caller_sender.getName() + " [" + Caller_sender + "])";
} else {
reason += " (実行元特定不能: " + sender.getName() + "|" + sender.toString() + ")";
}
try {
Pointjao Pjao = new Pointjao(offplayer);
boolean bool = Pjao.use(point, reason);
if (bool) {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」から" + point + "ポイントを減算しました。");
} else {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」から" + point + "ポイントを減算できませんでした。");
}
return true;
} catch (UnsupportedOperationException e) {
SendMessage(sender, cmd, "jaoポイントデータが存在しません。");
return true;
} catch (NullPointerException e) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
SendMessage(sender, cmd, "操作に失敗しました。");
SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
return true;
}
} else if (args[0].equalsIgnoreCase("pay")) {
// /jao pay player point reason
if (!(sender instanceof Player)) {
SendMessage(sender, cmd, "このコマンドはゲーム内から実行してください。");
return true;
}
Player player = (Player) sender;
OfflinePlayer offplayer = Bukkit.getOfflinePlayer(args[1]);
if (offplayer == null) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
}
int point;
try {
point = Integer.parseInt(args[2]);
} catch (NumberFormatException e) {
SendMessage(sender, cmd, "ポイントには数値を指定してください。");
return true;
}
if (point <= 0) {
SendMessage(sender, cmd, "ポイントは1以上を指定してください。");
return true;
}
String reason = "";
int c = 3;
while (args.length > c) {
reason += args[c];
if (args.length != (c + 1)) {
reason += " ";
}
c++;
}
String add_reason = "プレイヤー「" + offplayer.getName() + "」へ「" + reason + "」という理由での支払い。";
String use_reason = "プレイヤー「" + player.getName() + "」から「" + reason + "」という理由での支払い。";
try {
Pointjao playerPjao = new Pointjao(player);
Pointjao offplayerPjao = new Pointjao(offplayer);
boolean use_bool = playerPjao.use(point, add_reason);
if (use_bool) {
boolean add_bool = offplayerPjao.add(point, use_reason);
if (add_bool) {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」に" + point + "ポイントを支払いました。");
if (!Achievementjao.getAchievement(player, new AchievementType(23))) {
player.sendMessage(AchievementAPI.getPrefix() + "実績の解除中に問題が発生しました。もう一度お試しください。");
}
} else {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」に" + point + "ポイントを支払えませんでした。");
playerPjao.add(point, "『" + add_reason + "』の失敗による返却");
}
} else {
SendMessage(sender, cmd, "プレイヤー「" + offplayer.getName() + "」から" + point + "ポイントを減算できませんでした。");
}
return true;
} catch (UnsupportedOperationException e) {
SendMessage(sender, cmd, "jaoポイントデータが存在しません。");
return true;
} catch (NullPointerException e) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
SendMessage(sender, cmd, "操作に失敗しました。");
SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
return true;
}
}
}
if (!(sender instanceof Player)) {
SendMessage(sender, cmd, "このコマンドはゲーム内から実行してください。");
return true;
}
Player player = (Player) sender;
try {
Pointjao Pjao = new Pointjao(player);
int now = Pjao.get();
SendMessage(sender, cmd, "現在あなたが所持しているポイント数は" + now + "ポイントです。");
return true;
} catch (UnsupportedOperationException e) {
SendMessage(sender, cmd, "jaoポイントデータが存在しません。");
return true;
} catch (NullPointerException e) {
SendMessage(sender, cmd, "プレイヤーが見つかりません。");
return true;
} catch (ClassNotFoundException | SQLException e) {
BugReporter(e);
SendMessage(sender, cmd, "操作に失敗しました。");
SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
return true;
}
}
Aggregations