當前位置: 首頁>>代碼示例>>Java>>正文


Java ZonedDateTime.plusHours方法代碼示例

本文整理匯總了Java中java.time.ZonedDateTime.plusHours方法的典型用法代碼示例。如果您正苦於以下問題:Java ZonedDateTime.plusHours方法的具體用法?Java ZonedDateTime.plusHours怎麽用?Java ZonedDateTime.plusHours使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.plusHours方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: executeBan

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
    if (!PunishmentManager.ips_byUUID.containsKey(uuid))
        return false;
    String ip = PunishmentManager.ips_byUUID.get(uuid);
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " IP banned";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "IP banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
        try {
            insert_ban.setString(1, name);
            insert_ban.setString(2, uuid);
            insert_ban.setString(3, ip);
            insert_ban.setString(4, PunishmentType.IPBAN.toString());
            insert_ban.setString(5, fEndTime.toString());
            insert_ban.setString(6, reason);
            insert_ban.setString(7, banner);
            insert_ban.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed IP ban for " + name + ".");
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    if (banned != null && banned.isOnline())
        banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
    return true;
}
 
開發者ID:edasaki,項目名稱:ZentrelaCore,代碼行數:62,代碼來源:BanIPCommand.java

示例2: executeMute

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public boolean executeMute(String name, String uuid, String[] args, String muter, Player muted) {
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " muted";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "muted for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_mute = (PreparedStatement) ac_dub2[0];
        try {
            insert_mute.setString(1, name);
            insert_mute.setString(2, uuid);
            insert_mute.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
            insert_mute.setString(4, PunishmentType.MUTE.toString());
            insert_mute.setString(5, fEndTime.toString());
            insert_mute.setString(6, reason);
            insert_mute.setString(7, muter);
            insert_mute.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed mute for " + name + ".");
        PunishmentManager.checkMute(uuid);
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + muter + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    return true;
}
 
開發者ID:edasaki,項目名稱:ZentrelaCore,代碼行數:58,代碼來源:MuteCommand.java

示例3: executeBan

import java.time.ZonedDateTime; //導入方法依賴的package包/類
public boolean executeBan(String name, String uuid, String[] args, String banner, Player banned) {
    String time = args[1].toLowerCase();
    ZonedDateTime endTime = ZonedDateTime.now();
    String lengthDisplay = "";
    if (args[1].startsWith("perm")) {
        endTime = endTime.plusYears(1000);
        lengthDisplay = ChatColor.YELLOW + "permanently" + ChatColor.RED + " banned";
    } else {
        int amount = Integer.parseInt(time.replaceAll("[^0-9]", ""));
        if (time.endsWith("m")) {
            endTime = endTime.plusMinutes(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " minute" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("h")) {
            endTime = endTime.plusHours(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " hour" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("d")) {
            endTime = endTime.plusDays(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " day" + (amount != 1 ? "s" : "");
        } else if (time.endsWith("w")) {
            endTime = endTime.plusWeeks(amount);
            lengthDisplay = "banned for " + ChatColor.YELLOW + amount + " week" + (amount != 1 ? "s" : "");
        } else {
            return false;
        }
    }
    lengthDisplay += ChatColor.RESET;
    StringBuilder sb = new StringBuilder();
    for (int k = 2; k < args.length; k++) {
        sb.append(args[k]);
        sb.append(' ');
    }
    final ZonedDateTime fEndTime = endTime;
    String reason = sb.toString().trim();
    RScheduler.scheduleAsync(plugin, () -> {
        AutoCloseable[] ac_dub2 = SQLManager.prepare("INSERT INTO punishments (name, uuid, ip, type, endTime, reason, giver, startTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ");
        PreparedStatement insert_ban = (PreparedStatement) ac_dub2[0];
        try {
            insert_ban.setString(1, name);
            insert_ban.setString(2, uuid);
            insert_ban.setString(3, PunishmentManager.ips_byUUID.containsKey(uuid) ? PunishmentManager.ips_byUUID.get(uuid) : "");
            insert_ban.setString(4, PunishmentType.BAN.toString());
            insert_ban.setString(5, fEndTime.toString());
            insert_ban.setString(6, reason);
            insert_ban.setString(7, banner);
            insert_ban.setString(8, ZonedDateTime.now().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        SQLManager.execute(ac_dub2);
        SQLManager.close(ac_dub2);
        System.out.println("Executed ban for " + name + ".");
    });
    String announce = ChatColor.YELLOW + name + ChatColor.RED + " was " + lengthDisplay + ChatColor.RED + " by " + ChatColor.YELLOW + banner + ChatColor.RED + " for: " + ChatColor.WHITE + ChatColor.BOLD + reason + ChatColor.RED + ".";
    RMessages.announce(ChatColor.GRAY + "> " + announce);
    if (banned != null && banned.isOnline())
        banned.kickPlayer("You were " + lengthDisplay + " by " + banner + " for: " + reason + ".");
    return true;
}
 
開發者ID:edasaki,項目名稱:ZentrelaCore,代碼行數:59,代碼來源:BanCommand.java


注:本文中的java.time.ZonedDateTime.plusHours方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。