-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2f2b95
commit b0c4366
Showing
15 changed files
with
245 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
common/src/main/java/fi/fabianadrian/operatorlevel/common/level/LevelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fi.fabianadrian.operatorlevel.common.level; | ||
|
||
public interface LevelProvider<P> { | ||
int level(P player); | ||
} |
32 changes: 32 additions & 0 deletions
32
common/src/main/java/fi/fabianadrian/operatorlevel/common/level/LevelProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package fi.fabianadrian.operatorlevel.common.level; | ||
|
||
import fi.fabianadrian.operatorlevel.common.OperatorLevel; | ||
import org.slf4j.Logger; | ||
|
||
public abstract class LevelProviderFactory<P> { | ||
private final OperatorLevel<P> operatorLevel; | ||
protected final Logger logger; | ||
|
||
public LevelProviderFactory(OperatorLevel<P> operatorLevel) { | ||
this.operatorLevel = operatorLevel; | ||
this.logger = this.operatorLevel.logger(); | ||
} | ||
|
||
public LevelProvider<P> levelProvider() { | ||
if (!this.operatorLevel.config().luckPermsMeta()) { | ||
return permissionLevelProvider(); | ||
} | ||
|
||
LevelProvider<P> luckPermsProvider = luckPermsLevelProvider(); | ||
if (luckPermsProvider == null) { | ||
this.logger.warn("luckPermsMeta config option was enabled, but LuckPerms isn't enabled. Falling back to a permission-based check."); | ||
return permissionLevelProvider(); | ||
} | ||
|
||
return luckPermsProvider; | ||
} | ||
|
||
protected abstract PermissionLevelProvider<P> permissionLevelProvider(); | ||
|
||
protected abstract LuckPermsLevelProvider<P> luckPermsLevelProvider(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
common/src/main/java/fi/fabianadrian/operatorlevel/common/level/PermissionLevelProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fi.fabianadrian.operatorlevel.common.level; | ||
|
||
public abstract class PermissionLevelProvider<P> implements LevelProvider<P> { | ||
@Override | ||
public int level(P player) { | ||
int level = 0; | ||
for (int i = 4; i > 0; i--) { | ||
if (hasPermission(player, "operatorlevel.level." + i)) { | ||
level = i; | ||
break; | ||
} | ||
} | ||
return level; | ||
} | ||
|
||
protected abstract boolean hasPermission(P player, String permission); | ||
} |
29 changes: 29 additions & 0 deletions
29
common/src/main/java/fi/fabianadrian/operatorlevel/common/listener/LuckPermsListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package fi.fabianadrian.operatorlevel.common.listener; | ||
|
||
import fi.fabianadrian.operatorlevel.common.OperatorLevel; | ||
import fi.fabianadrian.operatorlevel.common.platform.Platform; | ||
import net.luckperms.api.LuckPerms; | ||
import net.luckperms.api.event.EventBus; | ||
import net.luckperms.api.event.user.UserDataRecalculateEvent; | ||
|
||
public final class LuckPermsListener<P> { | ||
private final Platform<P> platform; | ||
private final OperatorLevel<P> operatorLevel; | ||
|
||
public LuckPermsListener(Platform<P> platform, LuckPerms luckPerms, OperatorLevel<P> operatorLevel) { | ||
this.platform = platform; | ||
this.operatorLevel = operatorLevel; | ||
|
||
EventBus eventBus = luckPerms.getEventBus(); | ||
eventBus.subscribe(platform, UserDataRecalculateEvent.class, this::onUserDataRecalculate); | ||
} | ||
|
||
private void onUserDataRecalculate(UserDataRecalculateEvent event) { | ||
P player = this.platform.player(event.getUser().getUniqueId()); | ||
if (player == null) { | ||
return; | ||
} | ||
|
||
this.operatorLevel.updateLevel(player); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
common/src/main/java/fi/fabianadrian/operatorlevel/common/packet/PacketSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package fi.fabianadrian.operatorlevel.common.packet; | ||
|
||
import com.github.retrooper.packetevents.PacketEvents; | ||
import com.github.retrooper.packetevents.protocol.player.User; | ||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityStatus; | ||
|
||
public final class PacketSender { | ||
public void sendPacket(Object player, int level) { | ||
User user = PacketEvents.getAPI().getPlayerManager().getUser(player); | ||
if (user == null) { | ||
return; | ||
} | ||
|
||
WrapperPlayServerEntityStatus packet = new WrapperPlayServerEntityStatus(user.getEntityId(), 24 + level); | ||
user.sendPacketSilently(packet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.