Skip to content

Commit

Permalink
Added /silent
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 1, 2024
1 parent 13c8e0c commit 1281b16
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public enum Locale {
OPTIONS_SPECTATORS_ENABLED("OPTIONS.SPECTATORS_ENABLED"),
OPTIONS_SPECTATORS_DISABLED("OPTIONS.SPECTATORS_DISABLED"),
OPTIONS_SHOW_PLAYERS_ENABLED("OPTIONS.SHOWPLAYERS_ENABLED"),
OPTIONS_SHOW_PLAYERS_DISABLED("OPTIONS.SHOWPLAYERS_DISABLED");

OPTIONS_SHOW_PLAYERS_DISABLED("OPTIONS.SHOWPLAYERS_DISABLED"),
SILENT_ENABLED("OPTIONS.SILENT_ENABLED"),
SILENT_DISABLED("OPTIONS.SILENT_DISABLED");
private final String path;

public String format(Object... objects) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/lrxh/practice/Practice.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import me.lrxh.practice.arena.ArenaListener;
import me.lrxh.practice.arena.command.ArenaCommand;
import me.lrxh.practice.commands.admin.general.MainCommand;
import me.lrxh.practice.commands.admin.general.SilentCommand;
import me.lrxh.practice.commands.donater.FlyCommand;
import me.lrxh.practice.commands.user.EloCommand;
import me.lrxh.practice.commands.user.PingCommand;
Expand Down Expand Up @@ -211,7 +212,8 @@ private void registerCommands() {
new ViewInventoryCommand(),
new SpectateCommand(),
new PartyCommand(),
new EloCommand()
new EloCommand(),
new SilentCommand()
).forEach(command -> paperCommandManager.registerCommand(command));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package me.lrxh.practice.commands.admin.general;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.util.CC;
import me.lrxh.practice.util.LocationUtil;
import org.bukkit.Location;
import org.bukkit.entity.Player;

import java.io.IOException;


@CommandAlias("silent")
@CommandPermission("practice.admin.silent")
@Description("Silent Command for staff.")
public class SilentCommand extends BaseCommand {

@Default
public void silent(Player player) {
Profile profile = Profile.getProfiles().get(player.getUniqueId());
profile.setSilent(!profile.isSilent());
player.sendMessage(profile.isSilent() ? Locale.SILENT_ENABLED.format(player) : Locale.SILENT_DISABLED.format(player));
}
}
7 changes: 2 additions & 5 deletions src/main/java/me/lrxh/practice/commands/user/EloCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import co.aikar.commands.BaseCommand;
import co.aikar.commands.annotation.*;
import me.lrxh.practice.Locale;
import me.lrxh.practice.Practice;
import me.lrxh.practice.match.Match;
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.queue.Queue;
import me.lrxh.practice.util.BukkitReflection;
import me.lrxh.practice.util.CC;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand All @@ -23,7 +20,7 @@ public void elo(Player player) {
player.sendMessage(CC.translate("&eYour elo!"));
for (Queue queue : Practice.getInstance().getCache().getQueues()) {
if (queue.isRanked()) {
player.sendMessage(CC.translate("&c✦ &e"+ queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
player.sendMessage(CC.translate("&c✦ &e" + queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
}
}
player.sendMessage(CC.translate("&f&m---------------------------"));
Expand All @@ -44,7 +41,7 @@ public void pingOthers(Player player, String otherPlayer) {
player.sendMessage(CC.translate("&e" + otherPlayer + "'s elo!"));
for (Queue queue : Practice.getInstance().getCache().getQueues()) {
if (queue.isRanked()) {
player.sendMessage(CC.translate("&c✦ &e"+ queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
player.sendMessage(CC.translate("&c✦ &e" + queue.getKit().getName() + "&7: &f" + profile.getKitData().get(queue.getKit()).getElo()));
}
}
player.sendMessage(CC.translate("&f&m---------------------------"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

@CommandAlias("spectate")
@CommandAlias("spectate|spec")
@Description("Spectate a player.")
public class SpectateCommand extends BaseCommand {
@Default
Expand Down Expand Up @@ -45,7 +45,7 @@ public void execute(Player player, String targetName) {

Profile targetProfile = Profile.getByUuid(target.getUniqueId());

if (targetProfile == null || targetProfile.getState() != ProfileState.FIGHTING) {
if (targetProfile.getState() != ProfileState.FIGHTING) {
player.sendMessage(CC.RED + "That player is not in a match.");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ public void addSpectator(Player spectator, Player target) {

if (bukkitPlayer != null) {
VisibilityLogic.handle(bukkitPlayer);
bukkitPlayer.sendMessage(Locale.MATCH_NOW_SPECTATING.format(bukkitPlayer, spectator.getName()));
if(!profile.isSilent()){
bukkitPlayer.sendMessage(Locale.MATCH_NOW_SPECTATING.format(bukkitPlayer, spectator.getName()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import me.lrxh.practice.util.ChatComponentBuilder;
import me.lrxh.practice.util.PlayerUtil;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class Profile {
private QueueProfile queueProfile;
private Cooldown enderpearlCooldown;
private Cooldown voteCooldown;

private boolean silent = false;
public Profile(UUID uuid) {
this.uuid = uuid;
this.username = Bukkit.getPlayer(uuid).getName();
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/me/lrxh/practice/queue/QueueProfile.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.lrxh.practice.queue;

import lombok.Data;
import me.lrxh.practice.Locale;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.UUID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ public ItemStack getButtonItem(Player player) {
.replace("<kit>", queue.getKit().getName())
.replace("<type>", ranked ? "Unranked" : "Ranked");

if(queue.getQueuing() > 0){
if (queue.getQueuing() > 0) {
return new ItemBuilder(queue.getKit().getDisplayIcon())
.name(kitName)
.lore(lore)
.clearEnchantments()
.enchantment(Enchantment.DURABILITY)
.clearFlags()
.build();
}else{
} else {
return new ItemBuilder(queue.getKit().getDisplayIcon())
.name(kitName)
.lore(lore)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/lrxh/practice/util/PlaceholderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static List<String> format(List<String> lines, Player player) {
line = line.replaceAll("<ping>", String.valueOf((BukkitReflection.getPing(player))));
line = line.replaceAll("<theme>", CC.translate("&" + profile.getOptions().theme().getColor().getChar()));

if (line.contains("<silent>") && !profile.isSilent()){
continue;
}else{
line = line.replaceAll("<silent>", "&7&lSilent Mode");
}

if (profile.getState() == ProfileState.QUEUEING) {
line = line.replaceAll("<kit>", queueProfile.getQueue().getKit().getName());
line = line.replaceAll("<type>", queueProfile.getQueue().isRanked() ? "Ranked" : "Unranked");
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ OPTIONS:
TIME_SELECT: '&aYou have selected {0}!'
MENU_SOUNDS_ENABLED: '&aEnabled Menu sounds!'
MENU_SOUNDS_DISABLED: '&cDisabled Menu sounds!'
SILENT_ENABLED: '&aEnabled Silent Mode!'
SILENT_DISABLED: '&cDisabled Silent Mode!'
LEADERBOARD:
MESSAGE: '&aLeaderboards Refreshed!'
PARTY:
Expand Down

0 comments on commit 1281b16

Please sign in to comment.