diff --git a/src/main/java/flysystem/hj320/HJ320.java b/src/main/java/flysystem/hj320/HJ320.java index fadb4d9..02b3653 100644 --- a/src/main/java/flysystem/hj320/HJ320.java +++ b/src/main/java/flysystem/hj320/HJ320.java @@ -30,7 +30,7 @@ public void onDisable() { Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "-----------------------------------"); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[Plugin:"+plugin.getName()+" Un Loaded]"); Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "-----------------------------------"); - fly_system.storeplayerhours.clear(); + fly_system.storeplayermins.clear(); fly_system.isflyshitoncache.clear(); fly_system.isparticlesshitoncache.clear(); fly_system.getconfigloadinram.clear(); diff --git a/src/main/java/flysystem/hj320/config.java b/src/main/java/flysystem/hj320/config.java index 717a025..1a9b815 100644 --- a/src/main/java/flysystem/hj320/config.java +++ b/src/main/java/flysystem/hj320/config.java @@ -9,7 +9,7 @@ public class config { private static File serverinfo; - private static FileConfiguration config_set_hours; + private static FileConfiguration config_set_mins; public static void setup(){ serverinfo = Bukkit.getServer().getPluginManager().getPlugin(HJ320.getInstance().getName()).getDataFolder(); setupconfigspawn(); @@ -17,11 +17,11 @@ public static void setup(){ private static void setupconfigspawn(){ File file = new File(serverinfo, "config.yml"); if (!file.exists()){ try{ file.createNewFile(); }catch (IOException e){ } } - config_set_hours = YamlConfiguration.loadConfiguration(file); - config_set_hours.addDefault("time.mins", 3000); // 50 hours - config_set_hours.options().copyDefaults(true); + config_set_mins = YamlConfiguration.loadConfiguration(file); + config_set_mins.addDefault("time.mins", 3000); // 50 hours + config_set_mins.options().copyDefaults(true); HJ320.getInstance().saveConfig(); - try{ config_set_hours.save(file); }catch (IOException e){ Bukkit.getServer().getConsoleSender().sendMessage("Couldn't save file" + file); } + try{ config_set_mins.save(file); }catch (IOException e){ Bukkit.getServer().getConsoleSender().sendMessage("Couldn't save file" + file); } } - public static FileConfiguration gethoursconfig(){ return config_set_hours; } + public static FileConfiguration gethoursconfig(){ return config_set_mins; } } diff --git a/src/main/java/flysystem/hj320/fly_system.java b/src/main/java/flysystem/hj320/fly_system.java index 201a600..aedad4c 100644 --- a/src/main/java/flysystem/hj320/fly_system.java +++ b/src/main/java/flysystem/hj320/fly_system.java @@ -2,6 +2,7 @@ import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Particle; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -13,11 +14,15 @@ public class fly_system implements Listener { public static Map isflyshitoncache = new HashMap(); public static Map isparticlesshitoncache = new HashMap(); - public static Map storeplayerhours = new HashMap(); + public static Map storeplayermins = new HashMap(); public static Map getconfigloadinram = new HashMap(); public fly_system(HJ320 hj320) { hj320.getCommand("fly").setExecutor(new toggles()); + hj320.getCommand("reqtofly").setExecutor(new toggles()); hj320.getCommand("flyparticles").setExecutor(new toggles()); + hj320.getCommand("reqtoflyparticles").setExecutor(new toggles()); + hj320.getCommand("playtime").setExecutor(new toggles()); + hj320.getCommand("reqtoflyplaytime").setExecutor(new toggles()); Bukkit.getScheduler().runTaskTimer(hj320.getInstance(), new Runnable() { //run loop @Override @@ -27,10 +32,10 @@ public void run() { String mode = player.getGameMode().toString(); if (mode == "CREATIVE" || mode == "SPECTATOR") {player.setAllowFlight(true);} else { if(isplayerinflyon(player) == true && player.hasPermission("hj320.fly")||isplayerinflyon(player) == true && player.hasPermission("hj320.fly.req")){ - if(getplayershours(player) == null)return; + if(getplayersmins(player) == null)return; if(geconfigram() == null)return; - if (Integer.parseInt(getplayershours(player)) <= Integer.parseInt(geconfigram())) {player.setAllowFlight(false);} else { - if (Integer.parseInt(getplayershours(player)) >= Integer.parseInt(geconfigram())) {player.setAllowFlight(true);} + if (Integer.parseInt(getplayersmins(player)) <= Integer.parseInt(geconfigram())) {player.setAllowFlight(false);} else { + if (Integer.parseInt(getplayersmins(player)) >= Integer.parseInt(geconfigram())) {player.setAllowFlight(true);} if (player.isFlying()|| player.isGliding()) { if(isplayerinparton(player) == true && player.hasPermission("hj320.particles")){ player.getWorld().spawnParticle(Particle.SPIT, player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 4, 0, 0, 0, 0); @@ -49,7 +54,7 @@ public void run() { public void run() { for (Player player : Bukkit.getServer().getOnlinePlayers()) { if(player.isOnline() == true){ - int up5 = Integer.parseInt(storeplayerhours.get(player.getUniqueId()))+5; + int up5 = Integer.parseInt(storeplayermins.get(player.getUniqueId()))+5; // System.out.println("player = "+player.getName()); // System.out.println("up5 set to "+up5); @@ -60,8 +65,8 @@ public void run() { // System.out.println("player has hj320.fly = "+player.hasPermission("hj320.fly")); // System.out.println("player has hj320.particles = "+player.hasPermission("hj320.particles")); - storeplayerhours.replace(player.getUniqueId(), up5+""); - cache.save_user_data(player.getUniqueId(), "user_first_join_time", up5+""); + storeplayermins.replace(player.getUniqueId(), up5+""); + cache.save_user_data(player.getUniqueId(), "mins_user_has_played", up5+""); } } } @@ -82,8 +87,14 @@ public static String geconfigram() { if(getconfigloadinram.get("hj320hourconfig") == null)return "0"; return getconfigloadinram.get("hj320hourconfig"); } - public static String getplayershours(Player p) { - if(storeplayerhours.get(p.getUniqueId()) == null)return "0"; - return storeplayerhours.get(p.getUniqueId()); + public static String getplayersmins(Player p) { + if(storeplayermins.get(p.getUniqueId()) == null)return "0"; + return storeplayermins.get(p.getUniqueId()); } + public static String convert_time(int time) { + int hours = time / 60; + int minutes = time % 60; + return ChatColor.AQUA+"Time Played "+String.format("%02d:%02d", hours, minutes); + } + } diff --git a/src/main/java/flysystem/hj320/onjoin.java b/src/main/java/flysystem/hj320/onjoin.java index bcb78ab..288150d 100644 --- a/src/main/java/flysystem/hj320/onjoin.java +++ b/src/main/java/flysystem/hj320/onjoin.java @@ -16,18 +16,19 @@ private void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if(get_user_data_exists(player.getUniqueId()) == false){ - cache.save_user_data(player.getUniqueId(), "user_first_join_time", 0+""); + cache.save_user_data(player.getUniqueId(), "mins_user_has_played", 0+""); + cache.save_user_data(player.getUniqueId(), "user_first_join_time", System.currentTimeMillis()+""); cache.save_user_data(player.getUniqueId(), "fly_enabled","1"); cache.save_user_data(player.getUniqueId(), "particles_enabled","1"); } fly_system.isparticlesshitoncache.put(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), "particles_enabled"))); fly_system.isflyshitoncache.put(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), "fly_enabled"))); - fly_system.storeplayerhours.put(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), "user_first_join_time")); + fly_system.storeplayermins.put(player.getUniqueId(), cache.get_user_data(player.getUniqueId(), "mins_user_has_played")); } @EventHandler private void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); - fly_system.storeplayerhours.remove(player.getUniqueId()); + fly_system.storeplayermins.remove(player.getUniqueId()); fly_system.isflyshitoncache.remove(player.getUniqueId()); fly_system.isparticlesshitoncache.remove(player.getUniqueId()); } diff --git a/src/main/java/flysystem/hj320/toggles.java b/src/main/java/flysystem/hj320/toggles.java index 6356f3b..07525dc 100644 --- a/src/main/java/flysystem/hj320/toggles.java +++ b/src/main/java/flysystem/hj320/toggles.java @@ -35,7 +35,7 @@ public boolean onCommand (CommandSender sender, Command cmd, String label, Strin } } if (cmd.getName().equalsIgnoreCase("flyparticles")||cmd.getName().equalsIgnoreCase("reqtoflyparticles")) { - if (!sender.hasPermission("hj320.particles")) { + if (!sender.hasPermission("hj320.particles")||!sender.hasPermission("hj320.reqtoflyparticles")) { sender.sendMessage("You don't have permission to do this."); return true; } else { @@ -54,6 +54,19 @@ public boolean onCommand (CommandSender sender, Command cmd, String label, Strin } } } + if (cmd.getName().equalsIgnoreCase("playtime") || cmd.getName().equalsIgnoreCase("reqtoflyplaytime")) { + if (!sender.hasPermission("hj320.playtime") || !sender.hasPermission("hj320.reqtoflyplaytime")) { + sender.sendMessage("You don't have permission to do this."); + return true; + } else { + String mins = fly_system.getplayersmins(Bukkit.getPlayer(sender.getName())); + String playtimeshow = fly_system.convert_time(Integer.parseInt(mins)); + sender.sendMessage(playtimeshow); +// System.out.println("mins: " + mins); +// System.out.println("config time set: " + fly_system.geconfigram()); +// System.out.printf(playtimeshow); + } + } return false; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 33a4a34..fb5b86b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,7 +20,15 @@ commands: permission-message: You don't have permission for this command reqtoflyparticles: description: allows user to toggle fly particles - permission: hj320.particles + permission: hj320.reqtoflyparticles + permission-message: You don't have permission for this command + playtime: + description: tells user playtime + permission: hj320.playtime + permission-message: You don't have permission for this command + reqtoflyplaytime: + description: tells user playtime + permission: hj320.reqtoflyplaytime permission-message: You don't have permission for this command @@ -34,4 +42,10 @@ hj320.fly.*: hj320.fly: description: Gives access to fly hj320.flyparticles: - description: toggle fly particles \ No newline at end of file + description: toggle fly particles + hj320.reqtoflyparticles: + description: toggle fly particles + hj320.playtime: + description: tells users playtime + hj320.reqtoflyplaytime: + description: tells users playtime \ No newline at end of file