Skip to content

Commit

Permalink
up 修正控制台权限
Browse files Browse the repository at this point in the history
  • Loading branch information
Coloryr committed Nov 19, 2024
1 parent 883a368 commit b826022
Show file tree
Hide file tree
Showing 34 changed files with 239 additions and 257 deletions.
2 changes: 1 addition & 1 deletion core/AllMusic.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class AllMusic {
/**
* 插件版本号
*/
public static final String version = "3.3.0";
public static final String version = "3.3.1";
/**
* 配置文件版本号
*/
Expand Down
14 changes: 12 additions & 2 deletions core/command/CommandEX.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ else if (args[0].contains("&user"))
AllMusic.side.sendMessage(sender, AllMusic.getMessage().addMusic.noID);
}

private static boolean isAdmin(String name)
{
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(name)) {
return true;
}
}
return false;
}

/**
* 执行命令
*
Expand All @@ -224,15 +234,15 @@ public static void ex(Object sender, String name, String[] args) {
return;
}

if (AllMusic.side.checkPermission(name)) {
if (isAdmin(name) || AllMusic.side.checkPermission(sender)) {
command = commandAdminList.get(args[0]);
if (command != null) {
command.ex(sender, name, args);
return;
}
}
if (AllMusic.getConfig().needPermission &&
!AllMusic.side.checkPermission(name, "allmusic.addmusic"))
!AllMusic.side.checkPermission(sender, "allmusic.addmusic"))
AllMusic.side.sendMessage(sender, AllMusic.getMessage().command.noPer);
else {
switch (AllMusic.getConfig().defaultAddMusic) {
Expand Down
1 change: 0 additions & 1 deletion core/objs/config/ConfigObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public void init() {
minVote = 3;
voteTime = 30;
adminList = new HashSet<>();
adminList.add("console");
adminList.add("color_yr");
muteServer = new HashSet<>();
mutePlayer = new HashSet<>();
Expand Down
8 changes: 4 additions & 4 deletions core/side/BaseSide.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ public abstract class BaseSide {
/**
* 检查权限
*
* @param player 用户名
* @param player 用户
* @return 是否有权限
*/
public abstract boolean checkPermission(String player);
public abstract boolean checkPermission(Object player);

/**
* 检查权限
*
* @param player 用户名
* @param player 用户
* @param permission 权限
* @return 是否有权限
*/
public abstract boolean checkPermission(String player, String permission);
public abstract boolean checkPermission(Object player, String permission);

/**
* 是否需要播放
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -54,21 +56,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
ServerPlayerEntity player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof Entity) {
return ((Entity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -54,21 +56,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
ServerPlayerEntity player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof Entity) {
return ((Entity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -55,21 +57,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof Entity) {
return ((Entity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,21 +55,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof Entity) {
return ((Entity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import io.netty.buffer.ByteBuf;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.Entity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,21 +55,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof Entity) {
return ((Entity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
2 changes: 1 addition & 1 deletion fabric_1_20_2/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.9.23"
}
Expand Down
2 changes: 1 addition & 1 deletion fabric_1_20_2/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -55,21 +57,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof PlayerEntity) {
return ((PlayerEntity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
2 changes: 1 addition & 1 deletion fabric_1_20_6/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "1.9.23"
}
Expand Down
2 changes: 1 addition & 1 deletion fabric_1_20_6/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.coloryr.allmusic.server.side.fabric.event.MusicAddEvent;
import com.coloryr.allmusic.server.side.fabric.event.MusicPlayEvent;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -51,21 +53,18 @@ public void runTask(Runnable run1, int delay) {
}

@Override
public boolean checkPermission(String player) {
for (String item : AllMusic.getConfig().adminList) {
if (item.equalsIgnoreCase(player)) {
return true;
}
public boolean checkPermission(Object player) {
if (player instanceof MinecraftServer) {
return true;
}
var player1 = AllMusicFabric.server.getPlayerManager().getPlayer(player);
if (player1 == null)
return false;

return player1.hasPermissionLevel(2);
if (player instanceof PlayerEntity) {
return ((PlayerEntity) player).hasPermissionLevel(2);
}
return false;
}

@Override
public boolean checkPermission(String player, String permission) {
public boolean checkPermission(Object player, String permission) {
return checkPermission(player);
}

Expand Down
2 changes: 1 addition & 1 deletion fabric_1_21/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
id 'maven-publish'
id "org.jetbrains.kotlin.jvm" version "2.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion fabric_1_21/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit b826022

Please sign in to comment.