Makes encryption signs support admin decryption prevention
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
This commit is contained in:
@@ -64,12 +64,12 @@ Books without Borders has got your back!
|
|||||||
An in-game description of available commands is available through the /bwb command.
|
An in-game description of available commands is available through the /bwb command.
|
||||||
|
|
||||||
| Command | Alias | Arguments | Permission | Description |
|
| Command | Alias | Arguments | Permission | Description |
|
||||||
|----------------------|---------------|----------------------------------------------------------------------------------|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|----------------------|---------------|-----------------------------------------------------------------------------------------------------|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| /addbooktitlepage | bwbTitlePage | \[page index] \[title~description] | bookswithoutborders.addtitlepage | Adds a blank page, title page or chapter page depending on input and whether the book is signed. The title author separator (default `~`) is used to separate the input into title,paragraph1,paragraph2,... |
|
| /addbooktitlepage | bwbTitlePage | \[page index] \[title~description] | bookswithoutborders.addtitlepage | Adds a blank page, title page or chapter page depending on input and whether the book is signed. The title author separator (default `~`) is used to separate the input into title,paragraph1,paragraph2,... |
|
||||||
| /bookswithoutborders | bwb | None | | Displays information about commands (and permissions if the user has bookswithoutborders.admin) |
|
| /bookswithoutborders | bwb | None | | Displays information about commands (and permissions if the user has bookswithoutborders.admin) |
|
||||||
| /clearbook | bwbClear | None | bookswithoutborders.clear | Removes all text from the held un-signed book |
|
| /clearbook | bwbClear | None | bookswithoutborders.clear | Removes all text from the held un-signed book |
|
||||||
| /copybook | bwbCopy | \<# of copies> | bookswithoutborders.copy | Copies the book the player is holding |
|
| /copybook | bwbCopy | \<# of copies> | bookswithoutborders.copy | Copies the book the player is holding |
|
||||||
| /createbwbsign | bwbSign | \<give/encrypt/decrypt> \[book identifier/password] \[encryption style] | bookswithoutborders.signs | Creates a books without borders sign, as specified. This command is not restricted by the normal sign line text limit, and can load books with any name length for give signs. Encrypt and decrypts signs can be created manually just fine, but using this avoids manual formatting. |
|
| /createbwbsign | bwbSign | \<give/encrypt/decrypt> \[book identifier/password] \[encryption style] \[disable admin decryption] | bookswithoutborders.signs | Creates a books without borders sign, as specified. This command is not restricted by the normal sign line text limit, and can load books with any name length for give signs. Encrypt and decrypts signs can be created manually just fine, but using this avoids manual formatting. |
|
||||||
| /decryptbook | bwbDecrypt | \<key> | bookswithoutborders.decrypt | Decrypts the book the player is holding. "key" is required and MUST be IDENTICAL to the key used to encrypt the held book |
|
| /decryptbook | bwbDecrypt | \<key> | bookswithoutborders.decrypt | Decrypts the book the player is holding. "key" is required and MUST be IDENTICAL to the key used to encrypt the held book |
|
||||||
| /deletebook | bwbDelete | \<file name or number> | bookswithoutborders.delete | Deletes the specified file in the player's directory |
|
| /deletebook | bwbDelete | \<file name or number> | bookswithoutborders.delete | Deletes the specified file in the player's directory |
|
||||||
| /deletebookpage | bwbDeletePage | \<page> | bookswithoutborders.deletepage | Deletes one page from a book |
|
| /deletebookpage | bwbDeletePage | \<page> | bookswithoutborders.deletepage | Deletes one page from a book |
|
||||||
@@ -156,7 +156,9 @@ author). Use the `createbwbsign` command in order to specify book names of any l
|
|||||||
#### Encrypt sign
|
#### Encrypt sign
|
||||||
|
|
||||||
The **_encrypt_**-sign must have **\[Encrypt]** on its second line. The third line must contain the encryption key The
|
The **_encrypt_**-sign must have **\[Encrypt]** on its second line. The third line must contain the encryption key The
|
||||||
fourth line can be empty or contain "dna" for dna-based encryption.
|
fourth line can be empty or contain the encryption type (aes,dna,substitution,magic,onetimepad). If real encryption and
|
||||||
|
prevent admin decryption is enabled, "AES true" can be used as the encryption type to prevent admin decryption for any
|
||||||
|
book encrypted by the sign.
|
||||||
|
|
||||||
#### Decrypt sign
|
#### Decrypt sign
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import net.knarcraft.bookswithoutborders.gui.PagedBookIndex;
|
|||||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||||
|
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.knarcraft.knarlib.util.SignHelper;
|
import net.knarcraft.knarlib.util.SignHelper;
|
||||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||||
@@ -107,6 +108,9 @@ public class CommandCreateBwBSign implements TabExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TabCompletionHelper.filterMatchingStartsWith(encryptionStyles, arguments[2]);
|
return TabCompletionHelper.filterMatchingStartsWith(encryptionStyles, arguments[2]);
|
||||||
|
} else if (arguments.length == 4 && EncryptionStyle.getFromString(arguments[2]) != null &&
|
||||||
|
BooksWithoutBorders.getConfiguration().allowPreventAdminDecryption()) {
|
||||||
|
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeUtil.getBooleans(), arguments[3]);
|
||||||
}
|
}
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
@@ -119,14 +123,21 @@ public class CommandCreateBwBSign implements TabExecutor {
|
|||||||
* @return <p>True if the command was used correctly</p>
|
* @return <p>True if the command was used correctly</p>
|
||||||
*/
|
*/
|
||||||
private boolean createEncryptSign(@NotNull String[] arguments, @NotNull SignSide side) {
|
private boolean createEncryptSign(@NotNull String[] arguments, @NotNull SignSide side) {
|
||||||
if (arguments.length < 2 || arguments.length > 3) {
|
if (arguments.length < 2 || arguments.length > 4) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String password = arguments[1];
|
String password = arguments[1];
|
||||||
|
|
||||||
EncryptionStyle encryptionStyle = null;
|
EncryptionStyle encryptionStyle = null;
|
||||||
if (arguments.length == 3) {
|
boolean bypassAdminDecryption = false;
|
||||||
|
if (arguments.length == 3 || arguments.length == 4) {
|
||||||
encryptionStyle = EncryptionStyle.getFromString(arguments[2]);
|
encryptionStyle = EncryptionStyle.getFromString(arguments[2]);
|
||||||
|
|
||||||
|
// Retain admin decryption prevention on the sign
|
||||||
|
if (arguments.length == 4 && encryptionStyle == EncryptionStyle.AES &&
|
||||||
|
BooksWithoutBorders.getConfiguration().allowPreventAdminDecryption()) {
|
||||||
|
bypassAdminDecryption = Boolean.parseBoolean(arguments[3]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alter sign text
|
// Alter sign text
|
||||||
@@ -135,7 +146,7 @@ public class CommandCreateBwBSign implements TabExecutor {
|
|||||||
if (encryptionStyle == null) {
|
if (encryptionStyle == null) {
|
||||||
side.setLine(3, "");
|
side.setLine(3, "");
|
||||||
} else {
|
} else {
|
||||||
side.setLine(3, ChatColor.DARK_BLUE + encryptionStyle.toString());
|
side.setLine(3, ChatColor.DARK_BLUE + encryptionStyle.toString() + " " + bypassAdminDecryption);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.knarcraft.bookswithoutborders.listener;
|
package net.knarcraft.bookswithoutborders.listener;
|
||||||
|
|
||||||
|
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||||
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
|
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
|
||||||
import net.knarcraft.bookswithoutborders.config.translation.Placeholder;
|
import net.knarcraft.bookswithoutborders.config.translation.Placeholder;
|
||||||
@@ -183,8 +184,22 @@ public class SignEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
|
|
||||||
|
EncryptionStyle encryptionStyle;
|
||||||
|
boolean preventAdminDecryption = false;
|
||||||
|
String line = getCleanLine(lines[3]);
|
||||||
|
if (line.contains(" ")) {
|
||||||
|
String[] parts = line.split(" ");
|
||||||
|
encryptionStyle = Objects.requireNonNullElse(EncryptionStyle.getFromString(parts[0]), EncryptionStyle.AES);
|
||||||
|
preventAdminDecryption = Boolean.parseBoolean(parts[1]) &&
|
||||||
|
BooksWithoutBorders.getConfiguration().allowPreventAdminDecryption() &&
|
||||||
|
player.hasPermission(Permission.PREVENT_ADMIN_DECRYPTION.toString());
|
||||||
|
} else {
|
||||||
|
encryptionStyle = Objects.requireNonNullElse(EncryptionStyle.getFromString(getCleanLine(lines[3])), EncryptionStyle.AES);
|
||||||
|
}
|
||||||
|
|
||||||
ItemStack encryptedBook = EncryptedBookUtil.encryptBook(player, ItemSlot.fromEquipmentSlot(hand), getPassword(lines),
|
ItemStack encryptedBook = EncryptedBookUtil.encryptBook(player, ItemSlot.fromEquipmentSlot(hand), getPassword(lines),
|
||||||
getEncryptionStyle(lines), false);
|
encryptionStyle, preventAdminDecryption);
|
||||||
if (encryptedBook != null) {
|
if (encryptedBook != null) {
|
||||||
EncryptionUtil.markEncrypted(encryptedBook);
|
EncryptionUtil.markEncrypted(encryptedBook);
|
||||||
player.getInventory().setItem(hand, encryptedBook);
|
player.getInventory().setItem(hand, encryptedBook);
|
||||||
@@ -334,17 +349,6 @@ public class SignEventListener implements Listener {
|
|||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the encryption style specified on the given sign
|
|
||||||
*
|
|
||||||
* @param lines <p>The lines to parse</p>
|
|
||||||
* @return <p>The encryption style</p>
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
private EncryptionStyle getEncryptionStyle(@NotNull String[] lines) {
|
|
||||||
return Objects.requireNonNullElse(EncryptionStyle.getFromString(getCleanLine(lines[3])), EncryptionStyle.AES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the password specified on the given sign
|
* Gets the password specified on the given sign
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ commands:
|
|||||||
If creating an encrypt or a decrypt sign, the second argument will be treated as the encryption/decryption password
|
If creating an encrypt or a decrypt sign, the second argument will be treated as the encryption/decryption password
|
||||||
If creating an encrypt sign, the optional third argument is the encryption style to use. Possible values are
|
If creating an encrypt sign, the optional third argument is the encryption style to use. Possible values are
|
||||||
"dna", "substitution", "aes", "oneTimePad" and "magic"
|
"dna", "substitution", "aes", "oneTimePad" and "magic"
|
||||||
|
If enabled, the fourth arguments accept a positive boolean value (true/1) to disable admin decryption for encrypted books.
|
||||||
aliases:
|
aliases:
|
||||||
- bwbSign
|
- bwbSign
|
||||||
usage: /<command> <give/encrypt/decrypt> [book identifier/password] [encryption style]
|
usage: /<command> <give/encrypt/decrypt> [book identifier/password] [encryption style]
|
||||||
|
|||||||
Reference in New Issue
Block a user