Adds an enum for encryption styles and moves chat colors to variables to make them changeable
This commit is contained in:
parent
cedb93be40
commit
8f4e400309
File diff suppressed because it is too large
Load Diff
@ -384,7 +384,8 @@ public class BooksWithoutBordersListener implements Listener {
|
|||||||
boolean mainHand = hand == EquipmentSlot.HAND;
|
boolean mainHand = hand == EquipmentSlot.HAND;
|
||||||
if (heldItemType == Material.WRITTEN_BOOK) {
|
if (heldItemType == Material.WRITTEN_BOOK) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
eBook = BooksWithoutBorders.bwb.encryptBook(player, mainHand, lines[2].substring(2), lines[3].substring(2));
|
eBook = BooksWithoutBorders.bwb.encryptBook(player, mainHand, ChatColor.stripColor(lines[2]),
|
||||||
|
EncryptionStyle.getFromString(ChatColor.stripColor(lines[3])));
|
||||||
if (eBook != null) {
|
if (eBook != null) {
|
||||||
player.getInventory().setItem(hand, eBook);
|
player.getInventory().setItem(hand, eBook);
|
||||||
}
|
}
|
||||||
@ -398,7 +399,7 @@ public class BooksWithoutBordersListener implements Listener {
|
|||||||
* @param player <p>The player which clicked the sign</p>
|
* @param player <p>The player which clicked the sign</p>
|
||||||
*/
|
*/
|
||||||
private void giveBook(Sign sign, Player player) {
|
private void giveBook(Sign sign, Player player) {
|
||||||
String fileName = sign.getLine(2).substring(2);
|
String fileName = ChatColor.stripColor(sign.getLine(2));
|
||||||
boolean isLoadListNumber = false;
|
boolean isLoadListNumber = false;
|
||||||
|
|
||||||
for (int x = 0; x < fileName.length(); x++) {
|
for (int x = 0; x < fileName.length(); x++) {
|
||||||
@ -411,7 +412,7 @@ public class BooksWithoutBordersListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoadListNumber && sign.getLine(3).length() >= 2)
|
if (!isLoadListNumber && sign.getLine(3).length() >= 2)
|
||||||
fileName = sign.getLine(2).substring(2) + sign.getLine(3).substring(2);
|
fileName = ChatColor.stripColor(sign.getLine(2)) + ChatColor.stripColor(sign.getLine(3));
|
||||||
|
|
||||||
ItemStack newBook = BooksWithoutBorders.bwb.loadBook(player, fileName, "true", "public");
|
ItemStack newBook = BooksWithoutBorders.bwb.loadBook(player, fileName, "true", "public");
|
||||||
|
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package net.knarcraft.bookswithoutborders;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enum represents the different available encryption styles
|
||||||
|
*/
|
||||||
|
public enum EncryptionStyle {
|
||||||
|
DNA("dna"),
|
||||||
|
MAGIC("magic"),
|
||||||
|
SUBSTITUTION("");
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
EncryptionStyle(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets an encryption style given its name
|
||||||
|
* @param name <p>The name of the encryption style</p>
|
||||||
|
* @return <p>An encryption style or null if no match is found</p>
|
||||||
|
*/
|
||||||
|
public static EncryptionStyle getFromString(String name) {
|
||||||
|
for (EncryptionStyle style : EncryptionStyle.values()) {
|
||||||
|
if (style.name.equalsIgnoreCase(name)) {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user