Skip to content

Commit

Permalink
Implemented actions.
Browse files Browse the repository at this point in the history
Added actions with placeholders.
  • Loading branch information
Sean1472 committed Sep 1, 2020
1 parent 8b8ec96 commit b7b7759
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Commands:
Delay: 10
Actions:
- "[sendMessage] &7Twitter link: &cTWITTER.COM"
- "[broadcast] &7Follow our twitter!"
- "[commandPlayer] spawn"
- "[console] give %player% diamond 1"

Messages:
onCooldown: "&c&l(!) &fYou are on cooldown for another &c%remaining% seconds&f."
Expand Down
18 changes: 18 additions & 0 deletions src/me/sean0402/projectlinks/Listener/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import me.sean0402.projectlinks.OOP.Command;
import me.sean0402.projectlinks.ProjectLinks;
import me.sean0402.projectlinks.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
Expand All @@ -30,9 +32,25 @@ public void onCommandSend(PlayerCommandPreprocessEvent e) {
e.getPlayer().sendMessage(Utils.colour(ProjectLinks.getInstance().getConfig().getString("Messages.onCooldown").replace("%remaining%", String.valueOf(manager.getTimeReamining(e.getPlayer())))));
return;
}
runActions(e.getPlayer(), command);
ProjectLinks.getInstance().getVault().getEcon().withdrawPlayer(e.getPlayer(), command.getCost());
e.getPlayer().sendMessage(Utils.colour(ProjectLinks.getInstance().getConfig().getString("Messages.takenMoney").replace("%price%", String.valueOf(command.getCost()))));
}
}
}

private void runActions(Player player, Command command) {
for (String prefix : command.getActions()) {
String action = prefix.substring(prefix.indexOf("]") + 1).replace("%player%", player.getName()).replace("%Player%", player.getName()).trim();
if (prefix.startsWith("[sendMessage]")) {
player.sendMessage(Utils.colour(action));
} else if (prefix.startsWith("[broadcast]")) {
Bukkit.broadcastMessage(Utils.colour(action));
} else if (prefix.startsWith("[player]")) {
Bukkit.dispatchCommand(player, action);
} else if (prefix.startsWith("[console]")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), action);
}
}
}
}
5 changes: 4 additions & 1 deletion src/me/sean0402/projectlinks/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*/
public class Utils {

public static void sendMessage(Player player, String message) {
player.sendMessage(colour(message));
}
public static void sendHoverClickMessage(Player p, String chatMessage, String hoverMessage, String clickMessage, boolean sendTitle) {
p.spigot().sendMessage(new ComponentBuilder(colour(chatMessage))
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(colour(hoverMessage)).create()))
Expand All @@ -24,7 +27,7 @@ public static String colour(String message) {
}

public static void sendConsoleMessage(String... messages) {
for(String s : messages) Bukkit.getConsoleSender().sendMessage(colour(s));
for (String s : messages) Bukkit.getConsoleSender().sendMessage(colour(s));
}

public static void sendTitle(Player p, String title, String subTitle, int fadeIn, int stay, int fadeOut) {
Expand Down

0 comments on commit b7b7759

Please sign in to comment.