Skip to content

Commit

Permalink
Added sound check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean1472 committed Sep 1, 2020
1 parent b7b7759 commit 1ac1583
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
Commands:
discord:
Cost: 100
Delay: 10
Cooldown: 10
Actions:
- "[sendMessage] &7Discord link: &cDISCORD.COM"
twitter:
Cost: 100
Delay: 10
Cooldown: 10
Actions:
- "[sendMessage] &7Twitter link: &cTWITTER.COM"
- "[broadcast] &7Follow our twitter!"
Expand Down
9 changes: 8 additions & 1 deletion src/me/sean0402/projectlinks/Listener/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import me.sean0402.projectlinks.ProjectLinks;
import me.sean0402.projectlinks.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -28,7 +29,7 @@ public void onCommandSend(PlayerCommandPreprocessEvent e) {
for (Command command : ProjectLinks.commandList) {
if (message.equalsIgnoreCase(command.getCommandName())) {
e.setCancelled(true);
if (!manager.tryCooldown(e.getPlayer().getUniqueId(), command.getDelay())) {
if (!manager.tryCooldown(e.getPlayer().getUniqueId(), command.getCooldown())) {
e.getPlayer().sendMessage(Utils.colour(ProjectLinks.getInstance().getConfig().getString("Messages.onCooldown").replace("%remaining%", String.valueOf(manager.getTimeReamining(e.getPlayer())))));
return;
}
Expand All @@ -50,6 +51,12 @@ private void runActions(Player player, Command command) {
Bukkit.dispatchCommand(player, action);
} else if (prefix.startsWith("[console]")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), action);
} else if (prefix.startsWith("[sound]")) {
try {
player.playSound(player.getLocation(), Sound.valueOf(action), 1f, 1f);
} catch (Exception e) {
Utils.sendConsoleMessage("&c" + action + " &cis not a valid sound!");
}
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/me/sean0402/projectlinks/OOP/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
public class Command {

private final String commandName;
private final long delay;
private final long cooldown;
private final double cost;
private final List<String> actions;

public Command(String commandName, long delay, double cost, List<String> commands) {
public Command(String commandName, long cooldown, double cost, List<String> commands) {
this.commandName = commandName != null ? commandName : "Command invalid.";
this.delay = delay;
this.cooldown = cooldown;
this.cost = cost;
this.actions = commands != null ? commands : new ArrayList<>();
}
Expand All @@ -25,8 +25,8 @@ public String getCommandName() {
return commandName;
}

public long getDelay() {
return delay;
public long getCooldown() {
return cooldown;
}

public double getCost() {
Expand Down

0 comments on commit 1ac1583

Please sign in to comment.