Search in sources :

Example 6 with EscapeJailException

use of com.jaoafa.MyMaid2.Lib.EscapeJailException in project MyMaid2 by jaoafa.

the class Cmd_Jail 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 == 2) {
        if (args[0].equalsIgnoreCase("remove")) {
            String playername = args[1];
            Player player = Bukkit.getPlayerExact(playername);
            if (player == null) {
                OfflinePlayer offplayer = Bukkit.getOfflinePlayer(playername);
                if (offplayer == null) {
                    SendMessage(sender, cmd, "指定されたプレイヤー「" + playername + "」は見つかりませんでした。");
                    Player any_chance_player = Bukkit.getPlayer(playername);
                    if (any_chance_player != null) {
                        SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                    }
                    return true;
                }
                Jail.JailRemove(cmd, offplayer, sender);
                return true;
            }
            Jail.JailRemove(cmd, player, sender);
            return true;
        }
    } else if (args.length >= 3) {
        if (args[0].equalsIgnoreCase("area")) {
            String playername = args[1];
            Player player = Bukkit.getPlayerExact(playername);
            if (player == null) {
                SendMessage(sender, cmd, "指定されたプレイヤー「" + playername + "」は見つかりませんでした。");
                Player any_chance_player = Bukkit.getPlayer(playername);
                if (any_chance_player != null) {
                    SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                }
                return true;
            }
            boolean after = Boolean.valueOf(args[2]);
            Jail.JailArea(cmd, player, sender, after);
            return true;
        } else if (args[0].equalsIgnoreCase("block")) {
            String playername = args[1];
            Player player = Bukkit.getPlayerExact(playername);
            if (player == null) {
                SendMessage(sender, cmd, "指定されたプレイヤー「" + playername + "」は見つかりませんでした。");
                Player any_chance_player = Bukkit.getPlayer(playername);
                if (any_chance_player != null) {
                    SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                }
                return true;
            }
            boolean after = Boolean.valueOf(args[2]);
            Jail.JailBlock(cmd, player, sender, after);
            return true;
        } else if (args[0].equalsIgnoreCase("add")) {
            String playername = args[1];
            Player player = Bukkit.getPlayerExact(playername);
            String text = "";
            int c = 2;
            while (args.length > c) {
                text += args[c];
                if (args.length != (c + 1)) {
                    text += " ";
                }
                c++;
            }
            if (player == null) {
                OfflinePlayer offplayer = Bukkit.getOfflinePlayer(playername);
                if (offplayer == null) {
                    SendMessage(sender, cmd, "指定されたプレイヤー「" + playername + "」は見つかりませんでした。");
                    Player any_chance_player = Bukkit.getPlayer(playername);
                    if (any_chance_player != null) {
                        SendMessage(sender, cmd, "もしかして: " + any_chance_player.getName());
                    }
                    return true;
                }
                try {
                    Jail.JailAdd(offplayer, sender, text);
                } catch (ClassNotFoundException | NullPointerException | SQLException e) {
                    BugReporter(e);
                    SendMessage(sender, cmd, "操作に失敗しました。");
                    SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
                    SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
                    return true;
                } catch (EscapeJailException e) {
                    // でもオフラインプレイヤーだからこれが実行されることはない?
                    return true;
                }
                return true;
            }
            try {
                Jail.JailAdd(player, sender, text, false);
            } catch (ClassNotFoundException | NullPointerException | SQLException e) {
                BugReporter(e);
                SendMessage(sender, cmd, "操作に失敗しました。");
                SendMessage(sender, cmd, "詳しくはサーバコンソールをご確認ください");
                SendMessage(sender, cmd, "再度実行しなおすと動作するかもしれません。");
                return true;
            } catch (EscapeJailException e) {
                // EscapeJailアイテムで止められた
                // 痛くもない雷を落とす
                player.getWorld().strikeLightningEffect(player.getLocation());
                SendMessage(sender, cmd, "EscapeJailアイテムによって、Jailを無効化されてしまいました…。");
                SendMessage(player, cmd, "EscapeJailアイテムによって、" + sender.getName() + "からの「" + text + "」という理由によるJailを無効化しました!");
                return true;
            }
            return true;
        }
    } else if (args.length == 1) {
        if (args[0].equalsIgnoreCase("list")) {
            Jail.SendList(sender, cmd);
            return true;
        }
    }
    SendUsageMessage(sender, cmd);
    return true;
}
Also used : EscapeJailException(com.jaoafa.MyMaid2.Lib.EscapeJailException) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

EscapeJailException (com.jaoafa.MyMaid2.Lib.EscapeJailException)6 Player (org.bukkit.entity.Player)6 SQLException (java.sql.SQLException)5 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)5 EventHandler (org.bukkit.event.EventHandler)5 Inventory (org.bukkit.inventory.Inventory)5 ItemStack (org.bukkit.inventory.ItemStack)5 PotionMeta (org.bukkit.inventory.meta.PotionMeta)5 AchievementType (com.jaoafa.jaoSuperAchievement.jaoAchievement.AchievementType)4 OfflinePlayer (org.bukkit.OfflinePlayer)1