From 035acbfa1937caad4cf1626b917a36c898aaaf3a Mon Sep 17 00:00:00 2001 From: Super_ Date: Tue, 7 Jan 2020 15:53:31 -0500 Subject: [PATCH] more epic ! --- .../totalfreedommod/command/Command_ride.java | 2 +- .../totalfreedommod/command/Command_shop.java | 55 +++++++++++++++++++ .../command/FreedomCommand.java | 2 - .../command/FreedomCommandExecutor.java | 4 +- .../totalfreedommod/util/FUtil.java | 1 + 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java index 9902888b..fd0b2f54 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_ride.java @@ -112,7 +112,7 @@ public class Command_ride extends FreedomCommand player.sendMessage(ChatColor.GRAY + "Type " + ChatColor.DARK_GRAY + "/ride deny" + ChatColor.GRAY + " to deny the player permission."); player.sendMessage(ChatColor.GRAY + "Request will expire after 30 seconds."); RIDE_REQUESTS.put(player, playerSender); - timer.schedule(new TimerTask() + FreedomCommandExecutor.timer.schedule(new TimerTask() { @Override public void run() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java index 1b9640ef..e68f6487 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_shop.java @@ -1,7 +1,12 @@ package me.totalfreedom.totalfreedommod.command; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.TimerTask; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.shop.ShopData; @@ -19,6 +24,9 @@ import org.bukkit.inventory.meta.ItemMeta; @CommandParameters(description = "Access the shop", usage = "/ ") public class Command_shop extends FreedomCommand { + private final List locations = Arrays.asList("Sofa", "Car", "Bed", "Kitchen", "Garage", "Basement", "Home Study"); + private Map featureCooldown = new HashMap<>(); + @Override public boolean run(final CommandSender sender, final Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { @@ -34,6 +42,40 @@ public class Command_shop extends FreedomCommand msg(prefix + ChatColor.GREEN + "Balance: " + ChatColor.RED + sd.getCoins()); return true; } + if (args.length == 1) + { + if (featureCooldown.containsKey(sender) && featureCooldown.containsValue(args[0])) + { + msg("You're on cooldown for this feature.", ChatColor.RED); + return true; + } + Random r = new Random(); + switch (args[0]) + { + case "daily": + { + sd.setCoins(sd.getCoins() + 100); + plugin.sh.save(sd); + msg(prefix + ChatColor.GREEN + "You received your 100 coins!"); + cooldown(86400, args[0]); + return true; + } + case "search": + { + int amount = FUtil.random(5, 10); + String location = locations.get(r.nextInt(locations.size())); + sd.setCoins(sd.getCoins() + amount); + plugin.sh.save(sd); + msg(prefix + ChatColor.AQUA + location + ChatColor.GREEN + " - Found " + ChatColor.RED + amount + ChatColor.GREEN + " coins!"); + cooldown(30, args[0]); + return true; + } + default: + { + return false; + } + } + } if (args.length != 2) { return false; @@ -98,4 +140,17 @@ public class Command_shop extends FreedomCommand } } + private void cooldown(int seconds, String feature) + { + featureCooldown.put(sender, feature); + FreedomCommandExecutor.timer.schedule(new TimerTask() + { + @Override + public void run() + { + featureCooldown.remove(sender); + } + }, seconds * 1000); + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index 44780209..677db2b2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -2,7 +2,6 @@ package me.totalfreedom.totalfreedommod.command; import com.google.common.collect.Lists; import java.util.List; -import java.util.Timer; import lombok.Getter; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; @@ -33,7 +32,6 @@ public abstract class FreedomCommand extends AbstractCommandBase> extends Abstra private final TotalFreedomMod plugin; // - private Map commandCooldown = new HashMap<>(); - private final Timer timer = new Timer(); + public static Map commandCooldown = new HashMap<>(); + public static final Timer timer = new Timer(); public FreedomCommandExecutor(TotalFreedomMod plugin, AeroCommandHandler handler, String name, C command) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 822ed57e..092881cf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -3,6 +3,7 @@ package me.totalfreedom.totalfreedommod.util; import java.io.File; import java.io.FileFilter; import java.lang.reflect.Field; +import java.security.SecureRandom; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList;