diff --git a/src/config.yml b/src/config.yml index a37352d..ddb2213 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,6 +4,7 @@ birthday_announcement: "§c§lPeace§6§lAnd§a§lCube §ete souhaite un joyeux anniversaire %1s !" birthday_saved: "Ta date d'anniversaire a été enregistrée." +birthday_already_saved: "Tu as déjà enregistré ta date d'anniversaire." birthday_invalid: "La date d'anniversaire est invalide." player_birthday: "L'anniversaire de %1s est le %2s %3s." @@ -12,3 +13,8 @@ player_not_set: "Le joueur n'a pas de date d'anniversaire définie." birthdays_today: "Il y a %1s anniversaire(s) aujourd'hui : %2s" no_birthday_today: "Il n'y a aucun anniversaire aujourd'hui." + +# Rewards +# Use %1$s to use the player's name in a command +rewards: + - minecraft:give %1$s minecraft:player_head{SkullOwner:%1$s,display:{Name:'{"text":"Tête de %1$s","color":"yellow","italic":false}',Lore:['{"text":"Cadeau d\'anniversaire"}']},Enchantments:[{id:"minecraft:protection",lvl:4}],AttributeModifiers:[{AttributeName:"generic.armor",Name:"generic.armor",Amount:2,Operation:0,UUIDLeast:155648,UUIDMost:419097,Slot:"head"}]} diff --git a/src/fr/peaceandcube/pacbirthday/command/BirthdaysCommand.java b/src/fr/peaceandcube/pacbirthday/command/BirthdaysCommand.java index f937987..190a79e 100644 --- a/src/fr/peaceandcube/pacbirthday/command/BirthdaysCommand.java +++ b/src/fr/peaceandcube/pacbirthday/command/BirthdaysCommand.java @@ -1,8 +1,6 @@ package fr.peaceandcube.pacbirthday.command; -import java.text.SimpleDateFormat; import java.util.ArrayList; -import java.util.Date; import java.util.List; import org.bukkit.Bukkit; @@ -14,6 +12,7 @@ import org.bukkit.configuration.file.FileConfiguration; import fr.peaceandcube.pacbirthday.data.BirthdayData; +import fr.peaceandcube.pacbirthday.util.Utils; public class BirthdaysCommand implements CommandExecutor, TabExecutor { public FileConfiguration config = Bukkit.getPluginManager().getPlugin("PACBirthday").getConfig(); @@ -23,7 +22,7 @@ public class BirthdaysCommand implements CommandExecutor, TabExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (args.length == 0 && sender.hasPermission("pacbirthday.today")) { - List players = BirthdayData.getBirthdays(this.getCurrentDay()); + List players = BirthdayData.getBirthdays(Utils.getCurrentDay()); if (!players.isEmpty()) { String playerNames = ""; for (String player : players) { @@ -39,12 +38,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String return false; } - private String getCurrentDay() { - Date date = new Date(); - SimpleDateFormat format = new SimpleDateFormat("dd-MM"); - return format.format(date); - } - @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { return new ArrayList<>(); diff --git a/src/fr/peaceandcube/pacbirthday/command/SetBirthdayCommand.java b/src/fr/peaceandcube/pacbirthday/command/SetBirthdayCommand.java index fcece6c..a553487 100644 --- a/src/fr/peaceandcube/pacbirthday/command/SetBirthdayCommand.java +++ b/src/fr/peaceandcube/pacbirthday/command/SetBirthdayCommand.java @@ -18,6 +18,7 @@ public class SetBirthdayCommand implements CommandExecutor, TabExecutor { public FileConfiguration config = Bukkit.getPluginManager().getPlugin("PACBirthday").getConfig(); public String birthdaySaved = config.getString("birthday_saved"); + public String birthdayAlreadySaved = config.getString("birthday_already_saved"); public String birthdayInvalid = config.getString("birthday_invalid"); @Override @@ -26,13 +27,18 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String Player player = (Player) sender; if (args.length == 2 && player.hasPermission("pacbirthday.set")) { - if (this.isValidBirthday(args[0], args[1])) { - String monthNumber = String.format("%02d", Month.fromString(args[1]).getNumber()); - BirthdayData.saveBirthday(player, String.format("%02d", Integer.parseInt(args[0])) + "-" + monthNumber); - player.sendMessage(ChatColor.YELLOW + this.birthdaySaved); + if (BirthdayData.getBirthday(player) == null) { + if (this.isValidBirthday(args[0], args[1])) { + String monthNumber = String.format("%02d", Month.fromString(args[1]).getNumber()); + BirthdayData.saveBirthday(player, String.format("%02d", Integer.parseInt(args[0])) + "-" + monthNumber); + player.sendMessage(ChatColor.YELLOW + this.birthdaySaved); + } else { + player.sendMessage(ChatColor.RED + this.birthdayInvalid); + } } else { - player.sendMessage(ChatColor.RED + this.birthdayInvalid); + player.sendMessage(ChatColor.RED + this.birthdayAlreadySaved); } + return true; } } diff --git a/src/fr/peaceandcube/pacbirthday/event/PlayerJoin.java b/src/fr/peaceandcube/pacbirthday/event/PlayerJoin.java index 590dd2a..278d69e 100644 --- a/src/fr/peaceandcube/pacbirthday/event/PlayerJoin.java +++ b/src/fr/peaceandcube/pacbirthday/event/PlayerJoin.java @@ -2,9 +2,11 @@ import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -13,27 +15,37 @@ import org.bukkit.event.player.PlayerJoinEvent; import fr.peaceandcube.pacbirthday.data.BirthdayData; +import fr.peaceandcube.pacbirthday.util.Utils; public class PlayerJoin implements Listener { public FileConfiguration config = Bukkit.getPluginManager().getPlugin("PACBirthday").getConfig(); public String birthdayAnnouncement = config.getString("birthday_announcement"); + public List rewards = config.getStringList("rewards"); @EventHandler public void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); Server server = player.getServer(); - String currentDay = this.getCurrentDay(); + String currentDay = Utils.getCurrentDay(); String birthday = BirthdayData.getBirthday(player); if (currentDay.equals(birthday)) { server.broadcastMessage(String.format(ChatColor.LIGHT_PURPLE + this.birthdayAnnouncement, player.getName())); + + if (!currentDay.equals(this.getLastPlayed(player))) { + + // Execute all commands defined + for (String command : this.rewards) { + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format(command, player.getName())); + } + } } } - private String getCurrentDay() { - Date date = new Date(); - SimpleDateFormat format = new SimpleDateFormat("dd-MM"); - return format.format(date); + private String getLastPlayed(OfflinePlayer player) { + long timestamp = player.getLastPlayed(); + String date = new SimpleDateFormat("dd-MM").format(new Date(timestamp)); + return date; } } diff --git a/src/fr/peaceandcube/pacbirthday/util/Utils.java b/src/fr/peaceandcube/pacbirthday/util/Utils.java new file mode 100644 index 0000000..653d169 --- /dev/null +++ b/src/fr/peaceandcube/pacbirthday/util/Utils.java @@ -0,0 +1,13 @@ +package fr.peaceandcube.pacbirthday.util; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Utils { + + public static String getCurrentDay() { + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("dd-MM"); + return format.format(date); + } +} diff --git a/src/plugin.yml b/src/plugin.yml index 96c95d2..36a0c31 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: fr.peaceandcube.pacbirthday.PACBirthday name: PACBirthday -version: 1.0.1.1 +version: 1.1.0 author: Yanis48 api-version: 1.13