UTD
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/target/
|
||||||
27
src/main/java/eu/triler/BukkitColors/ApplyColors.java
Normal file
27
src/main/java/eu/triler/BukkitColors/ApplyColors.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package eu.triler.BukkitColors;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
|
public class ApplyColors {
|
||||||
|
|
||||||
|
public String applyColerCodes(String str) {
|
||||||
|
Pattern unicode = Pattern.compile("\\\\u\\+[a-fA-F0-9]{4}");
|
||||||
|
Matcher match = unicode.matcher(str);
|
||||||
|
while (match.find()) {
|
||||||
|
String code = str.substring(match.start(),match.end());
|
||||||
|
str = str.replace(code,Character.toString((char) Integer.parseInt(code.replace("\\u+",""),16)));
|
||||||
|
match = unicode.matcher(str);
|
||||||
|
}
|
||||||
|
Pattern pattern = Pattern.compile("&#[a-fA-F0-9]{6}");
|
||||||
|
match = pattern.matcher(str);
|
||||||
|
while (match.find()) {
|
||||||
|
String color = str.substring(match.start(),match.end());
|
||||||
|
str = str.replace(color,ChatColor.of(color.replace("&","")) + "");
|
||||||
|
match = pattern.matcher(str);
|
||||||
|
}
|
||||||
|
return ChatColor.translateAlternateColorCodes('&',str);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,48 @@
|
|||||||
package si.jernejtdo.LitePermissions.Spigot;
|
package si.jernejtdo.LitePermissions.Spigot;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import si.jernejtdo.LitePermissions.Spigot.Permissible.PlayerJoinInject;
|
import eu.triler.BukkitColors.ApplyColors;
|
||||||
|
import si.jernejtdo.LitePermissions.Spigot.Permissible.onPlayerLoginInject;
|
||||||
|
|
||||||
public class LitePermissions extends JavaPlugin {
|
public class LitePermissions extends JavaPlugin {
|
||||||
|
|
||||||
private static LitePermissions plugin;
|
private static LitePermissions plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
sendConsoleMessage("Plugin is starting.");
|
||||||
plugin.getServer().getPluginManager().registerEvents(new PlayerJoinInject(), plugin);
|
|
||||||
|
registerEvents(onPlayerLoginInject.class);
|
||||||
|
|
||||||
|
sendConsoleMessage("Plugin is enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
sendConsoleMessage("Plugin is disabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LitePermissions getPlugin() {
|
public static LitePermissions getPlugin() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T extends Listener> void registerEvents(Class<T> listenerClass) {
|
||||||
|
try {
|
||||||
|
T listener = listenerClass.getDeclaredConstructor().newInstance();
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||||
|
sendConsoleMessage("Listener &a" + listenerClass.getSimpleName() + "&f is registered.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendConsoleMessage(String message) {
|
||||||
|
ApplyColors ac = new ApplyColors();
|
||||||
|
String def = ac.applyColerCodes("&aLitePermissions &7| Message: &f" + message);
|
||||||
|
Bukkit.getConsoleSender().sendMessage(def);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,46 @@
|
|||||||
package si.jernejtdo.LitePermissions.Spigot.Permissible;
|
package si.jernejtdo.LitePermissions.Spigot.Permissible;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissibleBase;
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
import org.bukkit.permissions.ServerOperator;
|
import org.bukkit.permissions.ServerOperator;
|
||||||
|
|
||||||
|
import si.jernejtdo.LitePermissions.Spigot.LitePermissions;
|
||||||
|
|
||||||
public class CustomPermissible extends PermissibleBase {
|
public class CustomPermissible extends PermissibleBase {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
public CustomPermissible(ServerOperator opable) {
|
public CustomPermissible(ServerOperator opable) {
|
||||||
super(opable);
|
super(opable);
|
||||||
|
if (opable instanceof Player) {
|
||||||
|
this.player = (Player) opable;
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("CustomPermissible only supports Player instances");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(String inName) {
|
public boolean hasPermission(String inName) {
|
||||||
return checkPermissions(inName);
|
return checkPermissions(inName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasPermission(org.bukkit.permissions.Permission perm) {
|
public boolean hasPermission(org.bukkit.permissions.Permission perm) {
|
||||||
return checkPermissions(perm.toString());
|
return checkPermissions(perm.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkPermissions(String inName) {
|
public boolean checkPermissions(String inName) {
|
||||||
boolean has = false;
|
// You now have access to the player object
|
||||||
|
LitePermissions lp = LitePermissions.getPlugin();
|
||||||
/*
|
|
||||||
* My check logic
|
// Example: Check RamData or other storage here
|
||||||
* Get all permissions from RamData
|
// return RamData.hasPermission(player.getUniqueId(), inName);
|
||||||
* Check if player has permission
|
lp.sendConsoleMessage("&a"+player.getName()+"&f Permission(&a"+inName+"&f)");
|
||||||
*
|
|
||||||
*/
|
return false; // default deny
|
||||||
|
}
|
||||||
return has;
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ public class PermissionInjector {
|
|||||||
|
|
||||||
public static void injectCustomPermissible(Player player) {
|
public static void injectCustomPermissible(Player player) {
|
||||||
try {
|
try {
|
||||||
Field permField = player.getClass().getDeclaredField("perm");
|
Field permField = getPermField(player.getClass());
|
||||||
|
if (permField == null) {
|
||||||
|
System.err.println("Failed to find 'perm' field for player injection.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
permField.setAccessible(true);
|
permField.setAccessible(true);
|
||||||
CustomPermissible customPerm = new CustomPermissible(player);
|
CustomPermissible customPerm = new CustomPermissible(player);
|
||||||
permField.set(player, customPerm);
|
permField.set(player, customPerm);
|
||||||
@@ -16,4 +21,15 @@ public class PermissionInjector {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Field getPermField(Class<?> clazz) {
|
||||||
|
while (clazz != null) {
|
||||||
|
try {
|
||||||
|
return clazz.getDeclaredField("perm");
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
clazz = clazz.getSuperclass(); // walk up the hierarchy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package si.jernejtdo.LitePermissions.Spigot.Permissible;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
|
|
||||||
public class PlayerJoinInject implements Listener {
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onJoinInject(PlayerJoinEvent event) {
|
|
||||||
PermissionInjector.injectCustomPermissible(event.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package si.jernejtdo.LitePermissions.Spigot.Permissible;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
|
||||||
|
public class onPlayerLoginInject implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onLoginInject(PlayerLoginEvent event) {
|
||||||
|
PermissionInjector.injectCustomPermissible(event.getPlayer());
|
||||||
|
}
|
||||||
|
}
|
||||||
6
src/main/resources/plugin.yml
Normal file
6
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
name: LitePermissions
|
||||||
|
main: si.jernejtdo.LitePermissions.Spigot.LitePermissions
|
||||||
|
version: 1.0.0
|
||||||
|
api-version: 1.21.4
|
||||||
|
author: jernejtdo
|
||||||
|
description: A lightweight permissions plugin that injects custom permission handlers.
|
||||||
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
|
|||||||
#Generated by Maven Integration for Eclipse
|
#Generated by Maven Integration for Eclipse
|
||||||
#Wed Jul 09 14:33:12 CEST 2025
|
#Fri Jul 11 20:52:35 CEST 2025
|
||||||
artifactId=LitePermissions
|
artifactId=LitePermissions
|
||||||
groupId=si.jernejtdo
|
groupId=si.jernejtdo
|
||||||
m2e.projectLocation=C\:\\Users\\JernejHP\\Documents\\EclipseIDE\\JernejTDO\\LitePermissions
|
m2e.projectLocation=D\:\\Codespace\\JernejTDO\\LitePermissions
|
||||||
m2e.projectName=LitePermissions
|
m2e.projectName=LitePermissions
|
||||||
version=1.0
|
version=1.0
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
|||||||
|
D:\Codespace\JernejTDO\LitePermissions\src\main\java\si\jernejtdo\LitePermissions\Spigot\Permissible\PermissionInjector.java
|
||||||
|
D:\Codespace\JernejTDO\LitePermissions\src\main\java\si\jernejtdo\LitePermissions\Spigot\Permissible\onPlayerLoginInject.java
|
||||||
|
D:\Codespace\JernejTDO\LitePermissions\src\main\java\si\jernejtdo\LitePermissions\Spigot\LitePermissions.java
|
||||||
|
D:\Codespace\JernejTDO\LitePermissions\src\main\java\si\jernejtdo\LitePermissions\Spigot\Permissible\CustomPermissible.java
|
||||||
|
D:\Codespace\JernejTDO\LitePermissions\src\main\java\eu\triler\BukkitColors\ApplyColors.java
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user