Skip to content

Commit

Permalink
up 使用全小写名字
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Jul 3, 2024
1 parent 0b7a50d commit 9002459
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 58 deletions.
57 changes: 22 additions & 35 deletions core/AllMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AllMusic {
/**
* 插件版本号
*/
public static final String version = "3.1.4";
public static final String version = "3.1.5";
/**
* 配置文件版本号
*/
Expand All @@ -61,10 +61,6 @@ public class AllMusic {
* 正在播放的玩家
*/
private static final Set<String> nowPlayPlayer = new HashSet<>();
/**
* 暂时不往玩家发送数据包
*/
private static final Set<String> pauseSendPlayer = new HashSet<>();
/**
* 日志
*/
Expand Down Expand Up @@ -140,14 +136,13 @@ private static void messageCheck() {
* @param checkList 是否检查正在播放的列表
* @return 结果
*/
public static boolean isOK(String name, String server, boolean checkList) {
public static boolean isSkip(String name, String server, boolean checkList) {
try {
name = name.toLowerCase();
if (server != null && AllMusic.getConfig().muteServer.contains(server))
return true;
if (AllMusic.getConfig().mutePlayer.contains(name))
return true;
if (AllMusic.isPause(name))
return true;
if (!checkList)
return false;
return AllMusic.containNowPlay(name);
Expand All @@ -163,6 +158,7 @@ public static boolean isOK(String name, String server, boolean checkList) {
* @return 是否存在
*/
public static boolean containNowPlay(String player) {
player = player.toLowerCase();
return !nowPlayPlayer.contains(player);
}

Expand Down Expand Up @@ -199,6 +195,7 @@ public static MessageObj getMessage() {
* @param page 结果
*/
public static void addSearch(String player, SearchPageObj page) {
player = player.toLowerCase();
searchSave.put(player, page);
}

Expand All @@ -209,6 +206,7 @@ public static void addSearch(String player, SearchPageObj page) {
* @return 结果
*/
public static SearchPageObj getSearch(String player) {
player = player.toLowerCase();
return searchSave.get(player);
}

Expand All @@ -218,6 +216,7 @@ public static SearchPageObj getSearch(String player) {
* @param player 用户名
*/
public static void removeSearch(String player) {
player = player.toLowerCase();
searchSave.remove(player);
}

Expand All @@ -227,6 +226,7 @@ public static void removeSearch(String player) {
* @param player 用户名
*/
public static void addVote(String player) {
player = player.toLowerCase();
votePlayer.add(player);
}

Expand All @@ -236,6 +236,7 @@ public static void addVote(String player) {
* @param player 用户名
*/
public static void addPush(String player) {
player = player.toLowerCase();
pushPlayer.add(player);
}

Expand All @@ -255,6 +256,9 @@ public static void clearVote() {
votePlayer.clear();
}

/**
* 清空插歌
*/
public static void clearPush() {
pushPlayer.clear();
}
Expand All @@ -266,10 +270,12 @@ public static void clearPush() {
* @return 结果
*/
public static boolean containVote(String player) {
player = player.toLowerCase();
return votePlayer.contains(player);
}

public static boolean containPush(String player) {
player = player.toLowerCase();
return pushPlayer.contains(player);
}

Expand All @@ -279,6 +285,7 @@ public static boolean containPush(String player) {
* @param player 用户名
*/
public static void addNowPlayPlayer(String player) {
player = player.toLowerCase();
nowPlayPlayer.add(player);
}

Expand All @@ -288,8 +295,8 @@ public static void addNowPlayPlayer(String player) {
* @param player 用户名
*/
public static void removeNowPlayPlayer(String player) {
player = player.toLowerCase();
nowPlayPlayer.remove(player);
pauseSendPlayer.remove(player);
}

/**
Expand Down Expand Up @@ -444,46 +451,26 @@ private static void loadConfig() {
* @param player 用户名
*/
public static void joinPlay(String player) {
player = player.toLowerCase();
if (getConfig().mutePlayer.contains(player) || nowPlayPlayer.contains(player)) {
pauseSendPlayer.remove(player);
return;
}

String finalPlayer = player;
AllMusic.side.runTask(() -> {
if (PlayMusic.nowPlayMusic != null && PlayGo.url != null) {
AllMusic.side.sendHudPos(player);
AllMusic.side.sendMusic(player, PlayGo.url);
AllMusic.side.sendHudPos(finalPlayer);
AllMusic.side.sendMusic(finalPlayer, PlayGo.url);
if (!PlayMusic.nowPlayMusic.isUrl()) {
AllMusic.side.runTask(() ->
AllMusic.side.sendPic(player, PlayMusic.nowPlayMusic.getPicUrl()), 15);
AllMusic.side.sendPic(finalPlayer, PlayMusic.nowPlayMusic.getPicUrl()), 15);
}
AllMusic.side.runTask(() ->
AllMusic.side.sendPos(player, PlayMusic.musicNowTime + 1000), 40);
AllMusic.side.sendPos(finalPlayer, PlayMusic.musicNowTime + 1000), 40);
}

pauseSendPlayer.remove(player);
}, 40);
}

/**
* 将玩家添加到暂停发送列表
*
* @param player 玩家名
*/
public static void pauseSend(String player) {
pauseSendPlayer.add(player);
}

/**
* 暂停发送列表中是否存在玩家
*
* @param player 玩家名
* @return 是否存在
*/
public static boolean isPause(String player) {
return pauseSendPlayer.contains(player);
}

/**
* 读取配置文件
*
Expand Down
16 changes: 10 additions & 6 deletions core/objs/config/ConfigObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.coloryr.allmusic.server.core.AllMusic;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

/**
Expand Down Expand Up @@ -138,18 +139,21 @@ public void addBanMusic(String id) {
AllMusic.saveConfig();
}

public void addBanPlayer(String id) {
banPlayer.add(id);
public void addBanPlayer(String name) {
name = name.toLowerCase(Locale.ROOT);
banPlayer.add(name);
AllMusic.saveConfig();
}

public void addNoMusicPlayer(String ID) {
mutePlayer.add(ID);
public void addNoMusicPlayer(String name) {
name = name.toLowerCase(Locale.ROOT);
mutePlayer.add(name);
AllMusic.saveConfig();
}

public void removeNoMusicPlayer(String ID) {
mutePlayer.remove(ID);
public void removeNoMusicPlayer(String name) {
name = name.toLowerCase(Locale.ROOT);
mutePlayer.remove(name);
AllMusic.saveConfig();
}

Expand Down
2 changes: 1 addition & 1 deletion forge_1_16_5/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ modId="allmusic_server" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="3.1.4" #mandatory
version="3.1.5" #mandatory
# A display name for the mod
displayName="AllMusic Server" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
Expand Down
2 changes: 1 addition & 1 deletion forge_1_18_2/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ modId="allmusic_server" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="3.1.4" #mandatory
version="3.1.5" #mandatory
# A display name for the mod
displayName="AllMusic Serevr" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void sendHudLyric(String data) {
Object obj1 = pack(ComType.LYRIC, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
for (Player player : Bukkit.getOnlinePlayers()) {
if (AllMusic.isOK(player.getName(), null, true))
if (AllMusic.isSkip(player.getName(), null, true))
continue;
String name = player.getName();
SaveObj obj = HudUtils.get(name);
Expand All @@ -101,7 +101,7 @@ public void sendHudInfo(String data) {
Object obj1 = pack(ComType.INFO, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
for (Player player : Bukkit.getOnlinePlayers()) {
if (AllMusic.isOK(player.getName(), null, true))
if (AllMusic.isSkip(player.getName(), null, true))
continue;
String name = player.getName();
SaveObj obj = HudUtils.get(name);
Expand All @@ -121,7 +121,7 @@ public void sendHudPos(String name) {
Player player = Bukkit.getPlayer(name);
if (player == null)
return;
if (AllMusic.isOK(name, null, false))
if (AllMusic.isSkip(name, null, false))
return;
SaveObj obj = HudUtils.get(name);
String data = AllMusic.gson.toJson(obj);
Expand All @@ -144,7 +144,7 @@ public void sendHud(String name, HudType pos, String data) {
if (player == null)
return;

if (AllMusic.isOK(name, null, true))
if (AllMusic.isSkip(name, null, true))
return;
Object obj1 = null;
switch (pos) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public void sendHudList(String data) {
Object obj1 = pack(ComType.LIST, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
for (Player player : Bukkit.getOnlinePlayers()) {
if (AllMusic.isOK(player.getName(), null, true))
if (AllMusic.isSkip(player.getName(), null, true))
continue;
String name = player.getName();
SaveObj obj = HudUtils.get(name);
Expand Down Expand Up @@ -212,7 +212,7 @@ public void sendBar(String data) {
if (AllMusicBukkit.spigotSet) {
for (Player player : Bukkit.getOnlinePlayers()) {
try {
if (AllMusic.isOK(player.getName(), null, true))
if (AllMusic.isSkip(player.getName(), null, true))
continue;
SpigotApi.sendBar(player, data);
} catch (Exception e1) {
Expand All @@ -231,8 +231,9 @@ public void sendMusic(String data) {
Object obj1 = pack(ComType.PLAY, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
for (Player player : Bukkit.getOnlinePlayers()) {
if (AllMusic.isOK(player.getName(), null, false))
if (AllMusic.isSkip(player.getName(), null, false)) {
continue;
}
send(player, temp);
AllMusic.addNowPlayPlayer(player.getName());
}
Expand All @@ -248,8 +249,9 @@ protected void topSendMusic(String player, String data) {
Player player1 = Bukkit.getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isOK(player, null, false))
if (AllMusic.isSkip(player, null, false)) {
return;
}
Object obj1 = pack(ComType.PLAY, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
send(player1, temp);
Expand All @@ -265,7 +267,7 @@ public void sendPic(String data) {
Object obj1 = pack(ComType.IMG, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
for (Player player : Bukkit.getOnlinePlayers()) {
if (AllMusic.isOK(player.getName(), null, true))
if (AllMusic.isSkip(player.getName(), null, true))
continue;
String name = player.getName();
SaveObj obj = HudUtils.get(name);
Expand All @@ -285,7 +287,7 @@ public void sendPic(String player, String data) {
Player player1 = Bukkit.getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isOK(player1.getName(), null, true))
if (AllMusic.isSkip(player1.getName(), null, true))
return;
Object obj1 = pack(ComType.IMG, data, 0);
byte[] temp = (byte[]) arrayM.invoke(obj1);
Expand All @@ -302,7 +304,7 @@ public void sendPos(String player, int pos) {
Player player1 = Bukkit.getPlayer(player);
if (player1 == null)
return;
if (AllMusic.isOK(player1.getName(), null, true))
if (AllMusic.isSkip(player1.getName(), null, true))
return;
Object obj1 = pack(ComType.POS, null, pos);
byte[] temp = (byte[]) arrayM.invoke(obj1);
Expand Down Expand Up @@ -374,7 +376,7 @@ public void clearHud() {
@Override
public void topBq(String data) {
for (Player player : Bukkit.getOnlinePlayers()) {
if (!AllMusic.getConfig().mutePlayer.contains(player.getName())) {
if (!AllMusic.isSkip(player.getName(), null, true)) {
player.sendMessage(data);
}
}
Expand All @@ -391,7 +393,7 @@ public boolean needPlay() {
for (Player player : Bukkit.getOnlinePlayers()) {
if (CitizensNPC.isNPC(player))
online--;
else if (AllMusic.getConfig().mutePlayer.contains(player.getName())) {
else if (AllMusic.isSkip(player.getName(), null, false)) {
online--;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void sendMessageBqRun(String message, String end, String command)
endtext.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
send.addExtra(endtext);
for (Player player : Bukkit.getOnlinePlayers()) {
if (!AllMusic.getConfig().mutePlayer.contains(player.getName())) {
if (!AllMusic.isSkip(player.getName(), null, false)) {
player.spigot().sendMessage(send);
}
}
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.4
3.1.5

0 comments on commit 9002459

Please sign in to comment.