Skip to content

Commit 03d8938

Browse files
jstnfJRoy
andauthored
feat: Add /powertoollist (#6096)
<!-- EssentialsX feature submission guide ==================================== NOTE: Failure to fill out this template properly may result in your PR being delayed or ignored without warning. NOTE: Don't type between any arrows in the template, as this text will be hidden. This includes this header block and any other explanation text blocks. Want to discuss your PR before submitting it? Join the EssentialsX Development server: https://discord.gg/CUN7qVb EssentialsX is GPL ------------------ By contributing to EssentialsX, you agree to license your code under the GNU General Public License version 3, which can be found at the link below: https://github.com/EssentialsX/Essentials/blob/2.x/LICENSE Instructions ------------ If you are submitting a new feature, please follow the following steps: 1. Fill out the template in full. This includes providing screenshots and a link to the original feature request. If there isn't an existing feature request, we strongly recommend opening a new feature request BEFORE opening your PR to implement it, as this allows us to review whether we're likely to accept your feature in advance, and also allows us to discuss possible implementations for the feature. If there is no associated feature request, your PR may be delayed or rejected without warning. You can open a new feature request by following this link: https://github.com/EssentialsX/Essentials/issues/new/choose 2. If you are fixing a performance issue, please use the "Bug fix" PR template instead. The "bug fix" template is better suited to performance issues. 3. Include a demonstration. If you are adding commands, please provide screenshots and/or a video demonstration of the feature. Similarly, if you are adding a new API, please include a link to example code that takes advantage of your proposed API. This will aid us in reviewing PRs and speed up the process significantly. --> ### Information <!-- Replace #nnnn with the number of the original issue. If this PR implements features from multiple issues, you should repeat the phrase "closes #nnnn" for each issue. --> This PR closes #6095. ### Details **Proposed feature:** <!-- Type a description of your proposed feature below this line. --> This PR implements /powertoollist, which lists out all of a user's set powertools. Since all of a user's powertools reside within `UserData`, I utilized this Map to query through all of a user's powertools. **Environments tested:** <!-- Type the OS you have used below. --> OS: MacOS Apple chip <!-- Type the JDK version (from java -version) you have used below. --> Java version: 22.0.2 <!-- Put an "x" inside the boxes for the server software you have tested this bug fix on. If this feature does not apply to a server, strike through the server software using ~~strikethrough~~. If you have tested on other environments, add a new line with relevant details. --> - [ ] Most recent Paper version (1.XX.Y, git-Paper-BUILD) - [ ] CraftBukkit/Spigot/Paper 1.12.2 - [ ] CraftBukkit 1.8.8 ``` [20:36:06] [Server thread/INFO]: This server is running CraftBukkit version 4457-Spigot-73860e0-f0c8dd3 (MC: 1.21.4) (Implementing API version 1.21.4-R0.1-SNAPSHOT) [20:36:06] [Server thread/INFO]: Checking version, please wait... [20:36:06] [Thread-9/INFO]: You are running the latest version ``` **Demonstration:** <!-- Below this block, include screenshots/log snippets from before and after as necessary. If you have created or used a test case plugin, please link to a download of the plugin, source code and exact version used where possible. --> https://youtu.be/tgOr-fbHRAg --------- Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
1 parent 790644b commit 03d8938

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

Essentials/src/main/java/com/earth2me/essentials/UserData.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ public boolean hasPowerTools() {
271271
return !holder.powertools().isEmpty();
272272
}
273273

274+
public Map<String, List<String>> getAllPowertools() {
275+
return holder.powertools();
276+
}
277+
274278
public Location getLastLocation() {
275279
final LazyLocation lastLocation = holder.lastLocation();
276280
return lastLocation != null ? lastLocation.location() : null;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.earth2me.essentials.commands;
2+
3+
import com.earth2me.essentials.User;
4+
import com.earth2me.essentials.utils.StringUtil;
5+
import org.bukkit.Server;
6+
7+
import java.util.List;
8+
import java.util.Locale;
9+
import java.util.Map;
10+
11+
public class Commandpowertoollist extends EssentialsCommand {
12+
public Commandpowertoollist() {
13+
super("powertoollist");
14+
}
15+
16+
@Override
17+
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
18+
if (!user.hasPowerTools()) {
19+
user.sendTl("noPowerTools");
20+
return;
21+
}
22+
final Map<String, List<String>> powertools = user.getAllPowertools();
23+
for (Map.Entry<String, List<String>> entry : powertools.entrySet()) {
24+
final String itemName = entry.getKey().toLowerCase(Locale.ENGLISH).replaceAll("_", " ");
25+
final List<String> commands = entry.getValue();
26+
user.sendTl("powerToolList", StringUtil.joinList(commands), itemName);
27+
}
28+
}
29+
}

Essentials/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,8 @@ powertoolCommandUsage4=/<command> <cmd>
992992
powertoolCommandUsage4Description=Sets the powertool command of the held item to the given command
993993
powertoolCommandUsage5=/<command> a\:<cmd>
994994
powertoolCommandUsage5Description=Adds the given powertool command to the held item
995+
powertoollistCommandDescription=Lists all current powertools.
996+
powertoollistCommandUsage=/<command>
995997
powertooltoggleCommandDescription=Enables or disables all current powertools.
996998
powertooltoggleCommandUsage=/<command>
997999
ptimeCommandDescription=Adjust player's client time. Add @ prefix to fix.

Essentials/src/main/resources/plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ commands:
359359
description: Assigns a command to the item in hand.
360360
usage: /<command> [l:|a:|r:|c:|d:][command] [arguments] - {player} can be replaced by name of a clicked player.
361361
aliases: [epowertool,pt,ept]
362+
powertoollist:
363+
description: Lists all current powertools.
364+
usage: /<command>
365+
aliases: [epowertoollist,ptlist,eptlist]
362366
powertooltoggle:
363367
description: Enables or disables all current powertools.
364368
usage: /<command>

0 commit comments

Comments
 (0)