Skip to content

Commit

Permalink
[REM] Remove time variables
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJeterLP committed May 31, 2020
1 parent 009da95 commit 67673d5
Showing 1 changed file with 0 additions and 136 deletions.
136 changes: 0 additions & 136 deletions src/main/java/de/jeter/chatex/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,12 @@
import de.jeter.chatex.plugins.PluginManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import me.clip.placeholderapi.PlaceholderAPI;

public class Utils {

// Time Display Formats
private static final DateFormat dateMonths = new SimpleDateFormat("MM");
private static final DateFormat dateHours12 = new SimpleDateFormat("hh");
private static final DateFormat dateHours24 = new SimpleDateFormat("HH");
private static final DateFormat dateMinutes = new SimpleDateFormat("mm");
private static final DateFormat dateSeconds = new SimpleDateFormat("ss");

public static String translateColorCodes(String string, Player p) {
return p.hasPermission("chatex.chat.color") ? replaceColors(string) : string;
}
Expand Down Expand Up @@ -78,135 +66,11 @@ public static String replacePlayerPlaceholders(Player player, String format) {
result = result.replace("%player", player.getName());
result = result.replace("%world", player.getWorld().getName());
result = result.replace("%group", PluginManager.getInstance().getGroupNames(player).length > 0 ? PluginManager.getInstance().getGroupNames(player)[0] : "none");
result = replaceTime(result);
result = replaceColors(result);

return result;
}

private static String replaceTime(String message) {
Calendar calendar = Calendar.getInstance();
Date currentDate = calendar.getTime();
if (message.contains("%time")) {
DateFormat date = new SimpleDateFormat("HH:mm:ss");
message = message.replace("%time", date.format(currentDate));
}
// Check for padded versions first
if (message.contains("%MM")) {
message = message.replace("%MM", dateMonths.format(currentDate));
}
if (message.contains("%hh")) {
message = message.replace("%hh", dateHours12.format(currentDate));
}
if (message.contains("%HH")) {
message = message.replace("%HH", dateHours24.format(currentDate));
}
if (message.contains("%ii")) {
message = message.replace("%ii", dateMinutes.format(currentDate));
}
if (message.contains("%ss")) {
message = message.replace("%ss", dateSeconds.format(currentDate));
}

if (message.contains("%h")) {
final String hour = String.valueOf(calendar.get(Calendar.HOUR));
message = message.replace("%h", hour);
}
if (message.contains("%H")) {
final String hour = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
message = message.replace("%H", hour);
}
if (message.contains("%i")) {
final String minute = String.valueOf(calendar.get(Calendar.MINUTE));
message = message.replace("%i", minute);
}
if (message.contains("%s")) {
final String second = String.valueOf(calendar.get(Calendar.SECOND));
message = message.replace("%s", second);
}
if (message.contains("%a")) {
message = message.replace("%a", (calendar.get(Calendar.AM_PM) == 0) ? "am" : "pm");
}
if (message.contains("%A")) {
message = message.replace("%A", (calendar.get(Calendar.AM_PM) == 0) ? "AM" : "PM");
}
if (message.contains("%m")) {
final String month = String.valueOf(calendar.get(Calendar.MONTH));
message = message.replace("%m", month);
}
if (message.contains("%M")) {
String month = "";
final int monat = calendar.get(Calendar.MONTH) + 1;
switch (monat) {
case 1:
month = "January";
break;
case 2:
month = "February";
break;
case 3:
month = "March";
break;
case 4:
month = "April";
break;
case 5:
month = "May";
break;
case 6:
month = "June";
break;
case 7:
month = "July";
break;
case 8:
month = "August";
break;
case 9:
month = "September";
break;
case 10:
month = "October";
break;
case 11:
month = "November";
break;
case 12:
month = "December";
break;
default:
month = Locales.COMMAND_CLEAR_UNKNOWN.getString(null);
break;
}
message = message.replace("%M", month);
}

if (message.contains("%y")) {
final String year = String.valueOf(calendar.get(Calendar.YEAR));
message = message.replace("%m", year);
}

if (message.contains("%Y")) {
int year = calendar.get(Calendar.YEAR);
String year_new = String.valueOf(year);
year_new = year_new.replace("19", "").replace("20", "");
message = message.replace("%Y", year_new);
}

if (message.contains("%d")) {
final String day = String.valueOf(calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
message = message.replace("%d", day);
}

if (message.contains("%D")) {
final String day = String.valueOf(calendar.get(Calendar.DAY_OF_WEEK));
message = message.replace("%D", day);
}

message = replaceColors(message);
return message;
}

public static boolean checkForBlocked(String msg) {
List<String> blocked = Config.BLOCKED_WORDS.getStringList();
for (String block : blocked) {
Expand Down

0 comments on commit 67673d5

Please # to comment.