Skip to content

Commit

Permalink
some fixing and cleaning up
Browse files Browse the repository at this point in the history
cleaned up code
labeled everything to the proper name
fixed all the permissions so they all work
fixed all the commands so they all fully work
added /playtime command with its set permissions
added user_first_join_time in config for later use
  • Loading branch information
HeresJohnny320 committed Dec 11, 2022
1 parent 9fa0b5a commit 1069785
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/main/java/flysystem/hj320/HJ320.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/flysystem/hj320/config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

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();
}
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; }
}
31 changes: 21 additions & 10 deletions src/main/java/flysystem/hj320/fly_system.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,11 +14,15 @@
public class fly_system implements Listener {
public static Map<UUID, String> isflyshitoncache = new HashMap<UUID, String>();
public static Map<UUID, String> isparticlesshitoncache = new HashMap<UUID, String>();
public static Map<UUID, String> storeplayerhours = new HashMap<UUID, String>();
public static Map<UUID, String> storeplayermins = new HashMap<UUID, String>();
public static Map<String, String> getconfigloadinram = new HashMap<String, String>();
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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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+"");
}
}
}
Expand All @@ -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);
}

}
7 changes: 4 additions & 3 deletions src/main/java/flysystem/hj320/onjoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/flysystem/hj320/toggles.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
}
18 changes: 16 additions & 2 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -34,4 +42,10 @@ hj320.fly.*:
hj320.fly:
description: Gives access to fly
hj320.flyparticles:
description: toggle fly particles
description: toggle fly particles
hj320.reqtoflyparticles:
description: toggle fly particles
hj320.playtime:
description: tells users playtime
hj320.reqtoflyplaytime:
description: tells users playtime

0 comments on commit 1069785

Please sign in to comment.