Skip to content

Commit

Permalink
Implemented LuckPerms integration.
Browse files Browse the repository at this point in the history
Oh yes, someone asked this a long time ago, and its being done today xD
Fixed some dummy compiling error.
  • Loading branch information
larryTheCoder committed Jun 24, 2020
1 parent 899431d commit 2b0b34e
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 135 deletions.
34 changes: 31 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Adapted from the Wizardry License
~
~ Copyright (c) 2016-2020 larryTheCoder and contributors
~
~ Permission is hereby granted to any persons and/or organizations
~ using this software to copy, modify, merge, publish, and distribute it.
~ Said persons and/or organizations are not allowed to use the software or
~ any derivatives of the work for commercial use or any other means to generate
~ income, nor are they allowed to claim this software as their own.
~
~ The persons and/or organizations are also disallowed from sub-licensing
~ and/or trademarking this software without explicit permission from larryTheCoder.
~
~ Any persons and/or organizations using this software must disclose their
~ source code and have it publicly available, include this license,
~ provide sufficient credit to the original authors of the project (IE: larryTheCoder),
~ as well as provide a link to the original project.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
~ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
~ PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
~ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
~ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
~ USE OR OTHER DEALINGS IN THE SOFTWARE.
-->

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -70,9 +97,10 @@
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>me.lucko.luckperms</groupId>
<artifactId>luckperms-api</artifactId>
<version>4.3</version>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/com/larryTheCoder/ASkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
package com.larryTheCoder;

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.command.CommandSender;
import cn.nukkit.level.Level;
import cn.nukkit.level.generator.Generator;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.plugin.PluginManager;
import cn.nukkit.scheduler.ServerScheduler;
import cn.nukkit.utils.Config;
import cn.nukkit.utils.ConfigSection;
import cn.nukkit.utils.TextFormat;
Expand Down Expand Up @@ -60,6 +61,8 @@
import com.larryTheCoder.utils.Settings;
import com.larryTheCoder.utils.Utils;
import com.larryTheCoder.utils.integration.economy.Economy;
import com.larryTheCoder.utils.integration.luckperms.InternalPermission;
import com.larryTheCoder.utils.integration.luckperms.LuckPermsPermission;
import lombok.Getter;
import org.sql2o.Query;
import org.sql2o.data.Table;
Expand Down Expand Up @@ -212,14 +215,22 @@ private void initIslands() {
messages = new Messages(this);
messages.loadMessages();
levelCalcThread = new LevelCalcTask(this);
loadPermissionNodes();
//TopTen.topTenLoad();

pm.registerEvents(chatHandler, this);
pm.registerEvents(new IslandListener(this), this);
pm.registerEvents(new LavaCheck(this), this);
pm.registerEvents(new PlayerEvent(this), this);
ServerScheduler pd = getServer().getScheduler();
pd.scheduleRepeatingTask(new PluginTask(this), 20); // tick every 1 sec
}

private void loadPermissionNodes() {
Plugin plugin = Server.getInstance().getPluginManager().getPlugin("LuckPerms");
if (plugin == null) {
permissionHandler = new InternalPermission();
} else {
permissionHandler = new LuckPermsPermission();
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/larryTheCoder/ASkyBlockAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.larryTheCoder.listener.invitation.InvitationHandler;
import com.larryTheCoder.schematic.SchematicHandler;
import com.larryTheCoder.task.LevelCalcTask;
import com.larryTheCoder.utils.integration.luckperms.Permission;
import lombok.Getter;

public class ASkyBlockAPI extends PluginBase {
Expand Down Expand Up @@ -66,4 +67,6 @@ public class ASkyBlockAPI extends PluginBase {
protected SchematicHandler schematics;
@Getter
protected LevelCalcTask levelCalcThread;
@Getter
protected Permission permissionHandler;
}
4 changes: 0 additions & 4 deletions src/main/java/com/larryTheCoder/cache/CoopData.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,4 @@ public int hashCode() {

return i + super.hashCode();
}

public boolean isAdmin(Player p) {
return admins.stream().anyMatch(i -> i.equalsIgnoreCase(p.getName()));
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/larryTheCoder/cache/FastCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public void getIslandData(Position pos, Consumer<IslandData> resultOutput) {
getIslandData(id, resultOutput);
}

public void getIslandData(int id, Consumer<IslandData> resultOutput){
public void getIslandData(int id, Consumer<IslandData> resultOutput) {
FastCacheData result = dataCache.stream().filter(i -> i.anyIslandUidMatch(id)).findFirst().orElse(null);
if (result == null) {
plugin.getDatabase().pushQuery(new DatabaseManager.DatabaseImpl() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/larryTheCoder/command/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void registerCategories() {
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
Player p = sender.isPlayer() ? getPlugin().getServer().getPlayer(sender.getName()) : null;
if (!sender.hasPermission("is.command")) {
if (!getPlugin().getPermissionHandler().hasPermission(sender, "is.command")) {
sender.sendMessage(getLocale(p).errorNoPermission);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public List<String> getCommands() {
public boolean canUse(CommandSender sender, String command) {
switch (command.toLowerCase()) {
case "chat":
return sender.hasPermission("is.command.teamChat") && sender.isPlayer();
return hasPermission(sender, "is.command.teamChat") && sender.isPlayer();
case "messages":
return sender.hasPermission("is.command.messages") && sender.isPlayer();
return hasPermission(sender, "is.command.messages") && sender.isPlayer();
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public List<String> getCommands() {
public boolean canUse(CommandSender sender, String command) {
switch (command.toLowerCase()) {
case "accept":
return sender.hasPermission("is.command.accept") && sender.isPlayer();
return hasPermission(sender, "is.command.accept") && sender.isPlayer();
case "deny":
case "reject":
return sender.hasPermission("is.command.reject") && sender.isPlayer();
return hasPermission(sender, "is.command.reject") && sender.isPlayer();
case "invite":
return sender.hasPermission("is.command.invite") && sender.isPlayer();
return hasPermission(sender, "is.command.invite") && sender.isPlayer();
case "kickmember":
return sender.hasPermission("is.command.kick") && sender.isPlayer();
return hasPermission(sender, "is.command.kick") && sender.isPlayer();
case "quit":
return sender.hasPermission("is.command.quit") && sender.isPlayer();
return hasPermission(sender, "is.command.quit") && sender.isPlayer();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ public boolean canUse(CommandSender sender, String command) {
return sender.isOp();
case "expel":
case "kick":
return sender.hasPermission("is.command.expel") && sender.isPlayer();
return hasPermission(sender, "is.command.expel") && sender.isPlayer();
case "lobby":
case "spawn":
case "leave":
return sender.hasPermission("is.command.leave") && sender.isPlayer();
return hasPermission(sender, "is.command.leave") && sender.isPlayer();
case "locale":
return sender.hasPermission("is.command.lang") && sender.isPlayer();
return hasPermission(sender, "is.command.lang") && sender.isPlayer();
case "protection":
return sender.hasPermission("is.panel.protection") && sender.isPlayer();
return hasPermission(sender, "is.panel.protection") && sender.isPlayer();
case "settings":
return sender.hasPermission("is.panel.setting") && sender.isPlayer();
return hasPermission(sender, "is.panel.setting") && sender.isPlayer();
case "top":
return sender.hasPermission("is.topten");
return hasPermission(sender, "is.topten");
case "about":
return true;
case "download":
return sender.hasPermission("is.command.download");
return hasPermission(sender, "is.command.download");
default:
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ public List<String> getCommands() {
public boolean canUse(CommandSender sender, String command) {
switch (command) {
case "create":
return sender.hasPermission("is.create") && sender.isPlayer();
return hasPermission(sender, "is.create") && sender.isPlayer();
case "reset":
case "delete":
return sender.hasPermission("is.command.reset") && sender.isPlayer();
return hasPermission(sender, "is.command.reset") && sender.isPlayer();
case "home":
case "sethome":
return sender.hasPermission("is.command.home") && sender.isPlayer();
return hasPermission(sender, "is.command.home") && sender.isPlayer();
case "teleport":
return sender.hasPermission("is.command.teleport") && sender.isPlayer();
return hasPermission(sender, "is.command.teleport") && sender.isPlayer();
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public List<String> getCommands() {

@Override
public boolean canUse(CommandSender sender, String command) {
return sender.hasPermission("is.admin.command");
return hasPermission(sender, "is.admin.command");
}

@Override
Expand All @@ -89,7 +89,7 @@ public void execute(CommandSender sender, String commandLabel, String[] args) {

switch (args[0]) {
case "generate":
if (!sender.hasPermission("is.admin.generate")) {
if (!hasPermission(sender, "is.admin.generate")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public void execute(CommandSender sender, String commandLabel, String[] args) {
sender.sendMessage(getPlugin().getPrefix() + getPlugin().getLocale(pl).errorLevelGenerated);
break;
case "clear":
if (!sender.hasPermission("is.admin.clear")) {
if (!hasPermission(sender, "is.admin.clear")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
Expand All @@ -148,14 +148,14 @@ public void execute(CommandSender sender, String commandLabel, String[] args) {
break;
}

if (!sender.hasPermission("is.admin.kick")) {
if (!hasPermission(sender, "is.admin.kick")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
getPlugin().getIslandManager().kickPlayerByAdmin(sender, args[1]);
break;
case "rename":
if (!sender.hasPermission("is.admin.rename")) {
if (!hasPermission(sender, "is.admin.rename")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
Expand All @@ -177,7 +177,7 @@ public void execute(CommandSender sender, String commandLabel, String[] args) {
});
break;
case "cobblestats":
if (!sender.hasPermission("is.admin.cobblestats")) {
if (!hasPermission(sender, "is.admin.cobblestats")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public void execute(CommandSender sender, String commandLabel, String[] args) {
}
break;
case "delete":
if (!sender.hasPermission("is.admin.delete")) {
if (!hasPermission(sender, "is.admin.delete")) {
sender.sendMessage(getPlugin().getLocale(pl).errorNoPermission);
break;
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/larryTheCoder/command/category/SubCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@ public List<String> baseCommands() {
* @return The parameters required for the command.
*/
public abstract String getParameters(String commandName);

/**
* Check either the sender has the permission to execute this command
* using the libraries present in the server.
*
* @param sender The command sender that executes this command.
* @param permission The permission node name.
* @return {@code true} if the player has the permission.
*/
public boolean hasPermission(CommandSender sender, String permission) {
return ASkyBlock.get().getPermissionHandler().hasPermission(sender, permission);
}
}
9 changes: 2 additions & 7 deletions src/main/java/com/larryTheCoder/events/IslandCreateEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@
package com.larryTheCoder.events;

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.Event;
import cn.nukkit.event.HandlerList;
import cn.nukkit.level.Location;
import cn.nukkit.math.Vector2;
import com.larryTheCoder.ASkyBlock;
import com.larryTheCoder.cache.IslandData;
import lombok.Getter;

Expand All @@ -52,9 +47,9 @@ public class IslandCreateEvent extends SkyBlockEvent implements Cancellable {
private final int schematicId;

/**
* @param player The player class who is involved in this event
* @param player The player class who is involved in this event
* @param schematicId The schematic id of the island.
* @param island The data of the island.
* @param island The data of the island.
*/
public IslandCreateEvent(Player player, int schematicId, IslandData island) {
super(player, island);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/larryTheCoder/island/TeleportLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void safeTeleport(final Player player, final Location homeSweetHome, bool
final Location targetLoc = homeSweetHome.clone().add(0.5, 0, 0.5);
Utils.loadChunkAt(targetLoc);

if (player.hasPermission("is.bypass.wait") || (teleportDelay == 0) || force) {
if (plugin.getPermissionHandler().hasPermission(player, "is.bypass.wait") || (teleportDelay == 0) || force) {
player.teleport(targetLoc);
} else {
player.sendMessage(plugin.getPrefix() + plugin.getLocale(player).teleportDelay.replace("{0}", "" + teleportDelay));
Expand Down
Loading

0 comments on commit 2b0b34e

Please sign in to comment.