mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-26 17:05:01 +00:00
Work on the module list to support permissions
This commit is contained in:
parent
9fba895088
commit
54b803e09b
6
pom.xml
6
pom.xml
@ -279,6 +279,12 @@
|
|||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20220320</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<pluginRepositories>
|
<pluginRepositories>
|
||||||
|
@ -182,8 +182,7 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
|||||||
noPerms();
|
noPerms();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected void checkPermissions(String permission)
|
||||||
protected void checkRank(String permission)
|
|
||||||
{
|
{
|
||||||
//TODO: Not bothering with BukkitTelnet now.
|
//TODO: Not bothering with BukkitTelnet now.
|
||||||
if (sender instanceof Player player)
|
if (sender instanceof Player player)
|
||||||
@ -195,6 +194,23 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean checkPermissionsSilent(String permission)
|
||||||
|
{
|
||||||
|
//TODO: Not bothering with BukkitTelnet now.
|
||||||
|
if (sender instanceof ConsoleCommandSender)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (sender instanceof Player player)
|
||||||
|
{
|
||||||
|
if (!plugin.permissionHandler.hasPermission(player, permission))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected void checkRank(Rank rank)
|
protected void checkRank(Rank rank)
|
||||||
{
|
{
|
||||||
@ -408,7 +424,13 @@ public abstract class FreedomCommand implements CommandExecutor, TabCompleter
|
|||||||
|
|
||||||
public boolean func2()
|
public boolean func2()
|
||||||
{
|
{
|
||||||
if (!plugin.rm.getRank(sender).isAtLeast(perms.level()))
|
/*if (!plugin.rm.getRank(sender).isAtLeast(perms.level()))
|
||||||
|
{
|
||||||
|
msg(NO_PERMISSION);
|
||||||
|
return true;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
if (!checkPermissionsSilent(perms.permission()))
|
||||||
{
|
{
|
||||||
msg(NO_PERMISSION);
|
msg(NO_PERMISSION);
|
||||||
return true;
|
return true;
|
||||||
|
@ -76,6 +76,8 @@ public enum ConfigEntry
|
|||||||
|
|
||||||
PERMISSIONS_GROUPS_ADMIN(String.class, "permissions.groups.admin"),
|
PERMISSIONS_GROUPS_ADMIN(String.class, "permissions.groups.admin"),
|
||||||
PERMISSIONS_GROUPS_SENIOR(String.class, "permissions.groups.senior_admin"),
|
PERMISSIONS_GROUPS_SENIOR(String.class, "permissions.groups.senior_admin"),
|
||||||
|
|
||||||
|
PERMISSIONS_GROUPS_DEFAULT(String.class, "permissions.groups.default"),
|
||||||
DISCORD_TOKEN(String.class, "discord.token"),
|
DISCORD_TOKEN(String.class, "discord.token"),
|
||||||
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
|
DISCORD_REPORT_CHANNEL_ID(String.class, "discord.report_channel_id"),
|
||||||
DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"),
|
DISCORD_CHAT_CHANNEL_ID(String.class, "discord.chat_channel_id"),
|
||||||
|
@ -4,12 +4,15 @@ import me.totalfreedom.totalfreedommod.admin.Admin;
|
|||||||
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
||||||
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||||
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD;
|
||||||
|
import me.totalfreedom.totalfreedommod.permissions.handler.DefaultPermissionHandler;
|
||||||
|
import me.totalfreedom.totalfreedommod.permissions.handler.IPermissionHandler;
|
||||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.json.simple.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class Module_list extends HTTPDModule
|
public class Module_list extends HTTPDModule
|
||||||
@ -26,6 +29,29 @@ public class Module_list extends HTTPDModule
|
|||||||
if (params.get("json") != null && params.get("json").equals("true"))
|
if (params.get("json") != null && params.get("json").equals("true"))
|
||||||
{
|
{
|
||||||
final JSONObject responseObject = new JSONObject();
|
final JSONObject responseObject = new JSONObject();
|
||||||
|
if (!(plugin.permissionHandler instanceof DefaultPermissionHandler))
|
||||||
|
{
|
||||||
|
IPermissionHandler handler = plugin.permissionHandler;
|
||||||
|
final JSONObject players = new JSONObject();
|
||||||
|
|
||||||
|
Arrays.stream(handler.getGroups()).forEach(s ->
|
||||||
|
{
|
||||||
|
JSONArray array = new JSONArray();
|
||||||
|
Bukkit.getOnlinePlayers().stream().filter(player -> !plugin.al.isVanished(player.getName())).filter(player -> handler.getPrimaryGroup(player).equalsIgnoreCase(s)).forEach(player ->
|
||||||
|
{
|
||||||
|
array.put(player.getName());
|
||||||
|
});
|
||||||
|
players.put(s.toLowerCase(), array);
|
||||||
|
});
|
||||||
|
|
||||||
|
responseObject.put("players", players);
|
||||||
|
responseObject.put("online", Bukkit.getOnlinePlayers().stream().filter(player -> !plugin.al.isVanished(player.getName())).count());
|
||||||
|
responseObject.put("max", Bukkit.getMaxPlayers());
|
||||||
|
|
||||||
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString(4));
|
||||||
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
final JSONArray owners = new JSONArray();
|
final JSONArray owners = new JSONArray();
|
||||||
final JSONArray executives = new JSONArray();
|
final JSONArray executives = new JSONArray();
|
||||||
@ -44,27 +70,27 @@ public class Module_list extends HTTPDModule
|
|||||||
|
|
||||||
if (plugin.pl.getData(player).isMasterBuilder())
|
if (plugin.pl.getData(player).isMasterBuilder())
|
||||||
{
|
{
|
||||||
masterbuilders.add(player.getName());
|
masterbuilders.put(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FUtil.DEVELOPER_NAMES.contains(player.getName()))
|
if (FUtil.DEVELOPER_NAMES.contains(player.getName()))
|
||||||
{
|
{
|
||||||
developers.add(player.getName());
|
developers.put(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !FUtil.DEVELOPERS.contains(player.getName()))
|
if (ConfigEntry.SERVER_EXECUTIVES.getList().contains(player.getName()) && !FUtil.DEVELOPERS.contains(player.getName()))
|
||||||
{
|
{
|
||||||
executives.add(player.getName());
|
executives.put(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
if (ConfigEntry.SERVER_OWNERS.getList().contains(player.getName()))
|
||||||
{
|
{
|
||||||
owners.add(player.getName());
|
owners.put(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.al.isAdmin(player) && hasSpecialTitle(player))
|
if (!plugin.al.isAdmin(player) && hasSpecialTitle(player))
|
||||||
{
|
{
|
||||||
operators.add(player.getName());
|
operators.put(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getName()))
|
if (hasSpecialTitle(player) && plugin.al.isAdmin(player) && !plugin.al.isVanished(player.getName()))
|
||||||
@ -74,12 +100,12 @@ public class Module_list extends HTTPDModule
|
|||||||
{
|
{
|
||||||
case ADMIN:
|
case ADMIN:
|
||||||
{
|
{
|
||||||
admins.add(player.getName());
|
admins.put(player.getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SENIOR_ADMIN:
|
case SENIOR_ADMIN:
|
||||||
{
|
{
|
||||||
senioradmins.add(player.getName());
|
senioradmins.put(player.getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -102,11 +128,11 @@ public class Module_list extends HTTPDModule
|
|||||||
responseObject.put("online", FUtil.getFakePlayerCount());
|
responseObject.put("online", FUtil.getFakePlayerCount());
|
||||||
responseObject.put("max", server.getMaxPlayers());
|
responseObject.put("max", server.getMaxPlayers());
|
||||||
|
|
||||||
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString());
|
|
||||||
|
final NanoHTTPD.Response response = new NanoHTTPD.Response(NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_JSON, responseObject.toString(4));
|
||||||
response.addHeader("Access-Control-Allow-Origin", "*");
|
response.addHeader("Access-Control-Allow-Origin", "*");
|
||||||
return response;
|
return response;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
final StringBuilder body = new StringBuilder();
|
final StringBuilder body = new StringBuilder();
|
||||||
|
|
||||||
|
@ -40,4 +40,16 @@ public class DefaultPermissionHandler implements IPermissionHandler
|
|||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryGroup(@NotNull Player player)
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getGroups()
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException("Unable to use Bukkit's native permission system for groups!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,4 +17,9 @@ public interface IPermissionHandler
|
|||||||
|
|
||||||
boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName);
|
boolean inGroup(@NotNull OfflinePlayer player, @Nullable String groupName);
|
||||||
boolean inGroup(@NotNull Player player, @Nullable String groupName);
|
boolean inGroup(@NotNull Player player, @Nullable String groupName);
|
||||||
|
|
||||||
|
String getPrimaryGroup(@NotNull Player player);
|
||||||
|
|
||||||
|
|
||||||
|
String[] getGroups();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import me.totalfreedom.totalfreedommod.util.FLog;
|
|||||||
import net.milkbowl.vault.permission.Permission;
|
import net.milkbowl.vault.permission.Permission;
|
||||||
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
|
import nl.chimpgamer.networkmanager.api.NetworkManagerPlugin;
|
||||||
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
|
import nl.chimpgamer.networkmanager.api.NetworkManagerProvider;
|
||||||
|
import nl.chimpgamer.networkmanager.api.models.permissions.Group;
|
||||||
import nl.chimpgamer.networkmanager.api.models.permissions.PermissionPlayer;
|
import nl.chimpgamer.networkmanager.api.models.permissions.PermissionPlayer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
@ -92,4 +93,22 @@ public class NMPermissionHandler implements IPermissionHandler
|
|||||||
{
|
{
|
||||||
return this.inGroup((OfflinePlayer) player, groupName);
|
return this.inGroup((OfflinePlayer) player, groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getGroups()
|
||||||
|
{
|
||||||
|
return this.plugin.getPermissionManager().getGroups().values().stream().map(Group::getName).toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryGroup(@NotNull Player player)
|
||||||
|
{
|
||||||
|
PermissionPlayer permissionPlayer = this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId());
|
||||||
|
if (permissionPlayer == null)
|
||||||
|
{
|
||||||
|
FLog.warning("NM Perms: Couldn't find player's primary group due to them not be found our list");
|
||||||
|
return "default";
|
||||||
|
}
|
||||||
|
return this.plugin.getPermissionManager().getPermissionPlayer(player.getUniqueId()).getPrimaryGroup().getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,23 @@ public class VaultPermissionHandler implements IPermissionHandler
|
|||||||
return this.permissions.playerInGroup(player, groupName);
|
return this.permissions.playerInGroup(player, groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getGroups()
|
||||||
|
{
|
||||||
|
if (this.permissions == null)
|
||||||
|
{
|
||||||
|
FLog.debug("Can't use Vault permissions system for group listing, there is no plugin using Vault permissions.");
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
return this.permissions.getGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryGroup(@NotNull Player player)
|
||||||
|
{
|
||||||
|
return this.permissions.getPrimaryGroup(player);
|
||||||
|
}
|
||||||
|
|
||||||
public Permission getPermissions()
|
public Permission getPermissions()
|
||||||
{
|
{
|
||||||
return permissions;
|
return permissions;
|
||||||
|
@ -59,6 +59,7 @@ permissions:
|
|||||||
groups:
|
groups:
|
||||||
admin: "Administrator"
|
admin: "Administrator"
|
||||||
senior_admin: "Senior-Administrator"
|
senior_admin: "Senior-Administrator"
|
||||||
|
default: "Guest"
|
||||||
|
|
||||||
# Discord
|
# Discord
|
||||||
discord:
|
discord:
|
||||||
|
Loading…
Reference in New Issue
Block a user