Skip to content

Commit

Permalink
Features added/updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Brov3r committed Jul 7, 2024
1 parent cb06bae commit 992b05b
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 12 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- Added `getCommandArgs` method for different prefixes
- Added `sendMessageToAdmins` method
- Added tools for working with Lua
- Added `setPlayerAccessLevel` method
- Added `getRoleName` method in `AccessLevel` class
- Fixed creation of folders when copying nested configs
- Updated plugin example

# AvrixLoader v1.1.1

Expand Down
28 changes: 22 additions & 6 deletions docs/javadoc/com/avrix/enums/AccessLevel.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,19 @@ <h2>Method Summary</h2>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the priority of a given access level.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#valueOf(java.lang.String)" class="member-name-link">valueOf</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;name)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the enum constant of this class with the specified name.</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#getRoleName()" class="member-name-link">getRoleName</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Returns the name of this access level.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>[]</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#values()" class="member-name-link">values</a>()</code></div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a></code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#valueOf(java.lang.String)" class="member-name-link">valueOf</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;name)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns the enum constant of this class with the specified name.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static <a href="AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>[]</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#values()" class="member-name-link">values</a>()</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Returns an array containing the constants of this enum class, in
the order they are declared.</div>
</div>
Expand Down Expand Up @@ -284,6 +289,17 @@ <h3>getPriority</h3>
</section>
</li>
<li>
<section class="detail" id="getRoleName()">
<h3>getRoleName</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a></span>&nbsp;<span class="element-name">getRoleName</span>()</div>
<div class="block">Returns the name of this access level.</div>
<dl class="notes">
<dt>Returns:</dt>
<dd>access level name</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="fromString(java.lang.String)">
<h3>fromString</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type"><a href="AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a></span>&nbsp;<span class="element-name">fromString</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;text)</span></div>
Expand Down
57 changes: 57 additions & 0 deletions docs/javadoc/com/avrix/utils/PlayerUtils.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,24 @@ <h2>Method Summary</h2>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Kick a player from the server</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#setPlayerAccessLevel(java.lang.String,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;playerName,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Sets the access level of a player by their username.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static void</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#setPlayerAccessLevel(zombie.characters.IsoPlayer,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel</a><wbr>(zombie.characters.IsoPlayer&nbsp;player,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Sets the access level of a player.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code>static void</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4"><code><a href="#setPlayerAccessLevel(zombie.core.raknet.UdpConnection,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel</a><wbr>(zombie.core.raknet.UdpConnection&nbsp;player,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab1 method-summary-table-tab4">
<div class="block">Sets the access level of a player.</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -191,6 +209,45 @@ <h3>PlayerUtils</h3>
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="setPlayerAccessLevel(java.lang.String,com.avrix.enums.AccessLevel)">
<h3>setPlayerAccessLevel</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">setPlayerAccessLevel</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html" title="class or interface in java.lang" class="external-link">String</a>&nbsp;playerName,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</span></div>
<div class="block">Sets the access level of a player by their username.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>playerName</code> - the username of the player</dd>
<dd><code>accessLevel</code> - the new access level to set</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="setPlayerAccessLevel(zombie.characters.IsoPlayer,com.avrix.enums.AccessLevel)">
<h3>setPlayerAccessLevel</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">setPlayerAccessLevel</span><wbr><span class="parameters">(zombie.characters.IsoPlayer&nbsp;player,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</span></div>
<div class="block">Sets the access level of a player.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>player</code> - the IsoPlayer object representing the player</dd>
<dd><code>accessLevel</code> - the new access level to set</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="setPlayerAccessLevel(zombie.core.raknet.UdpConnection,com.avrix.enums.AccessLevel)">
<h3>setPlayerAccessLevel</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">setPlayerAccessLevel</span><wbr><span class="parameters">(zombie.core.raknet.UdpConnection&nbsp;player,
<a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a>&nbsp;accessLevel)</span></div>
<div class="block">Sets the access level of a player.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>player</code> - the UdpConnection object representing the player's connection</dd>
<dd><code>accessLevel</code> - the new access level to set</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="getPlayerAccessLevel(zombie.core.raknet.UdpConnection)">
<h3>getPlayerAccessLevel</h3>
<div class="member-signature"><span class="modifiers">public static</span>&nbsp;<span class="return-type"><a href="../enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a></span>&nbsp;<span class="element-name">getPlayerAccessLevel</span><wbr><span class="parameters">(zombie.core.raknet.UdpConnection&nbsp;connection)</span></div>
Expand Down
16 changes: 16 additions & 0 deletions docs/javadoc/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,10 @@ <h2 class="title" id="I:G">G</h2>
<dd>
<div class="block">Getting a map of registered user commands</div>
</dd>
<dt><a href="com/avrix/enums/AccessLevel.html#getRoleName()" class="member-name-link">getRoleName()</a> - Method in enum class com.avrix.enums.<a href="com/avrix/enums/AccessLevel.html" title="enum class in com.avrix.enums">AccessLevel</a></dt>
<dd>
<div class="block">Returns the name of this access level.</div>
</dd>
<dt><a href="com/avrix/plugin/ServiceManager.html#getService(java.lang.Class)" class="member-name-link">getService(Class&lt;T&gt;)</a> - Static method in class com.avrix.plugin.<a href="com/avrix/plugin/ServiceManager.html" title="class in com.avrix.plugin">ServiceManager</a></dt>
<dd>
<div class="block">Returns the registered service by its interface.</div>
Expand Down Expand Up @@ -4400,6 +4404,18 @@ <h2 class="title" id="I:S">S</h2>
<dd>
<div class="block">Sets a map in the YAML file under the specified key.</div>
</dd>
<dt><a href="com/avrix/utils/PlayerUtils.html#setPlayerAccessLevel(java.lang.String,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel(String, AccessLevel)</a> - Static method in class com.avrix.utils.<a href="com/avrix/utils/PlayerUtils.html" title="class in com.avrix.utils">PlayerUtils</a></dt>
<dd>
<div class="block">Sets the access level of a player by their username.</div>
</dd>
<dt><a href="com/avrix/utils/PlayerUtils.html#setPlayerAccessLevel(zombie.characters.IsoPlayer,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel(IsoPlayer, AccessLevel)</a> - Static method in class com.avrix.utils.<a href="com/avrix/utils/PlayerUtils.html" title="class in com.avrix.utils">PlayerUtils</a></dt>
<dd>
<div class="block">Sets the access level of a player.</div>
</dd>
<dt><a href="com/avrix/utils/PlayerUtils.html#setPlayerAccessLevel(zombie.core.raknet.UdpConnection,com.avrix.enums.AccessLevel)" class="member-name-link">setPlayerAccessLevel(UdpConnection, AccessLevel)</a> - Static method in class com.avrix.utils.<a href="com/avrix/utils/PlayerUtils.html" title="class in com.avrix.utils">PlayerUtils</a></dt>
<dd>
<div class="block">Sets the access level of a player.</div>
</dd>
<dt><a href="com/avrix/utils/YamlFile.html#setShort(java.lang.String,short)" class="member-name-link">setShort(String, short)</a> - Method in class com.avrix.utils.<a href="com/avrix/utils/YamlFile.html" title="class in com.avrix.utils">YamlFile</a></dt>
<dd>
<div class="block">Sets a short value in the YAML file.</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/javadoc/member-search-index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions example-plugin/src/main/java/com/avrix/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void onInitialize() {
YamlFile test = loadConfig("test/test.yml");
YamlFile test2 = loadConfig("test/test2.yml"); // The file will be created

test2.save();

System.out.println("[#] Hello world from " + getMetadata().getName());
System.out.println("[$] Test.yml: " + test.getString("test"));
System.out.println("[$] config.yml: " + getDefaultConfig().getString("config"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
* Test Command
*/
@CommandName("test")
@CommandAccessLevel(AccessLevel.ADMIN)
@CommandExecutionScope(CommandScope.BOTH)
@CommandAccessLevel(AccessLevel.NONE)
@CommandExecutionScope(CommandScope.CHAT)
@CommandChatReturn("Return text")
public class TestCommand implements Command {
@CommandDescription("Command description")
public class TestCommand extends Command {
/**
* Performing a chat command action
*
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/avrix/enums/AccessLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum AccessLevel {
* Role name
*/
private final String roleName;

/**
* Access Level Priority
*/
Expand All @@ -70,6 +70,15 @@ public int getPriority() {
return this.priority;
}

/**
* Returns the name of this access level.
*
* @return access level name
*/
public String getRoleName() {
return this.roleName;
}

/**
* Converts a string to the corresponding AccessLevel. Returns NONE if no match is found.
*
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/avrix/plugin/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ private void copyConfigFromJar(String fileName, File destination) {
*/
public final synchronized YamlFile loadConfig(String configPath) {
File configFromFolder = getConfigFolder().toPath().resolve(configPath).toFile();

try {
File parentDir = configFromFolder.getParentFile();
if (parentDir != null && !parentDir.exists()) {
if (!parentDir.mkdirs()) {
throw new IOException("[!] Failed to create directories for: " + configFromFolder.getAbsolutePath());
}
}

configPath = configPath.trim();

if (!configPath.endsWith(".yml")) {
Expand Down
76 changes: 75 additions & 1 deletion src/main/java/com/avrix/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,92 @@
import com.avrix.enums.AccessLevel;
import com.avrix.events.EventManager;
import zombie.characters.IsoPlayer;
import zombie.commands.PlayerType;
import zombie.core.logger.LoggerManager;
import zombie.core.raknet.UdpConnection;
import zombie.core.znet.SteamUtils;
import zombie.network.GameServer;
import zombie.network.ServerWorldDatabase;
import zombie.network.Userlog;
import zombie.network.chat.ChatServer;

import java.sql.SQLException;

/**
* A set of tools for player management, monitoring and analysis
*/
public class PlayerUtils {
/**
* Sets the access level of a player by their username.
*
* @param playerName the username of the player
* @param accessLevel the new access level to set
*/
public static void setPlayerAccessLevel(String playerName, AccessLevel accessLevel) {
setPlayerAccessLevel(getPlayerByPartialUsername(playerName), accessLevel);
}

/**
* Sets the access level of a player.
*
* @param player the IsoPlayer object representing the player
* @param accessLevel the new access level to set
*/
public static void setPlayerAccessLevel(IsoPlayer player, AccessLevel accessLevel) {
setPlayerAccessLevel(getUdpConnectionByPlayer(player), accessLevel);
}

/**
* Sets the access level of a player.
*
* @param player the UdpConnection object representing the player's connection
* @param accessLevel the new access level to set
*/
public static void setPlayerAccessLevel(UdpConnection player, AccessLevel accessLevel) {
if (player == null) return;

IsoPlayer isoPlayer = getPlayerByUdpConnection(player);
if (isoPlayer == null) return;

if (!ServerWorldDatabase.instance.containsUser(player.username)) {
System.out.printf("[!] Player '%s' is not in the whitelist!%n", player.username);
return;
}

if (isoPlayer.networkAI != null) {
isoPlayer.networkAI.setCheckAccessLevelDelay(5000L);
}

boolean isAdmin = accessLevel.equals(AccessLevel.ADMIN);

if (isAdmin) {
ChatServer.getInstance().joinAdminChat(isoPlayer.OnlineID);
} else {
ChatServer.getInstance().leaveAdminChat(isoPlayer.OnlineID);
}

isoPlayer.setGodMod(isAdmin);
isoPlayer.setGhostMode(isAdmin);
isoPlayer.setInvisible(isAdmin);
isoPlayer.setNoClip(isAdmin);
isoPlayer.setShowAdminTag(isAdmin);

isoPlayer.accessLevel = accessLevel.getRoleName();
player.accessLevel = PlayerType.fromString(accessLevel.getRoleName());

GameServer.sendPlayerExtraInfo(isoPlayer, null);

try {
ServerWorldDatabase.instance.setAccessLevel(player.username, accessLevel.getRoleName());
} catch (Exception e) {
System.out.printf("[!] Failed to update access level for player '%s' to '%s' in database: %s%n", player.username, accessLevel.getRoleName(), e.getMessage());
}

System.out.printf("[#] Console granted '%s' access level on '%s'", accessLevel.getRoleName(), player.username);
LoggerManager.getLogger("admin").write(String.format("Console granted '%s' access level on '%s'", accessLevel.getRoleName(), player.username));
ChatUtils.sendMessageToPlayer(player, String.format("[#] Your access level is set to '%s'", accessLevel.getRoleName()));
}

/**
* Retrieves the access level of a player based on their {@link UdpConnection}.
*
Expand All @@ -34,7 +108,7 @@ public static AccessLevel getPlayerAccessLevel(UdpConnection connection) {
public static AccessLevel getPlayerAccessLevel(IsoPlayer player) {
return AccessLevel.fromString(player.accessLevel);
}

/**
* Getting a player's instance on his connection
*
Expand Down

0 comments on commit 992b05b

Please sign in to comment.