Skip to content

Commit

Permalink
Merge branch 'main' of github.com:diademiemi/Lineation
Browse files Browse the repository at this point in the history
  • Loading branch information
x86-39 committed Oct 31, 2021
2 parents 3f98d62 + 6acd2ed commit b94e4e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/java/me/diademiemi/lineation/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class Message {
public static String ERROR_UNKNOWN_LINE;
public static String ERROR_NULL_AREA;
public static String ERROR_INVALID_NAME;
public static String ERROR_INVALID_BLOCK;
public static String ERROR_NOT_START;
public static String ERROR_NOT_FINISH;
public static String ERROR_NO_CHECKPOINT;
Expand Down Expand Up @@ -69,6 +70,7 @@ public static void reloadMessages() {
ERROR_UNKNOWN_LINE = PREFIX + format(messageConfig.getConfig().getString("ERROR_UNKNOWN_LINE"));
ERROR_NULL_AREA = PREFIX + format(messageConfig.getConfig().getString("ERROR_NULL_AREA"));
ERROR_INVALID_NAME = PREFIX + format(messageConfig.getConfig().getString("ERROR_INVALID_NAME"));
ERROR_INVALID_BLOCK = PREFIX + format(messageConfig.getConfig().getString("ERROR_INVALID_BLOCK"));
ERROR_NOT_START = PREFIX + format(messageConfig.getConfig().getString("ERROR_NOT_START"));
ERROR_NOT_FINISH = PREFIX + format(messageConfig.getConfig().getString("ERROR_NOT_FINISH"));
ERROR_NO_CHECKPOINT = PREFIX + format(messageConfig.getConfig().getString("ERROR_NO_CHECKPOINT"));
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/me/diademiemi/lineation/command/CommandExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import me.diademiemi.lineation.line.LineIO;
import me.diademiemi.lineation.line.LineTools;

import java.util.Arrays;

/**
* Command class for listening for lineation command
*
Expand Down Expand Up @@ -118,7 +120,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
&& !args[3].equalsIgnoreCase("create")
&& !args[3].equalsIgnoreCase("remove")
&& !args[3].equalsIgnoreCase("list")) {
new Line(args[3], args[2]);
new Line(args[3], args[2].toLowerCase());
sender.sendMessage(Message.SUCCESS_LINE_CREATED.replace("$LINE$", args[3]));
} else sender.sendMessage(Message.ERROR_INVALID_NAME);
} else sender.sendMessage(Message.ERROR_LINE_EXISTS);
Expand Down Expand Up @@ -382,8 +384,11 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (args.length > 4) {
if (sender.hasPermission("lineation.line.option.blocksequence")) {
try {
line.setBlockSequence(args[4].toLowerCase());
sender.sendMessage(Message.SUCCESS_OPTION_SET);
if (line.setBlockSequence(String.join(",", Arrays.copyOfRange(args, 4, args.length)).replaceAll("\\s", "").toLowerCase())) {
sender.sendMessage(Message.SUCCESS_OPTION_SET);
} else {
sender.sendMessage(Message.ERROR_INVALID_BLOCK);
}
} catch (Exception e) {
sender.sendMessage(Message.ERROR_UNKNOWN_ARGS);
}
Expand Down
24 changes: 20 additions & 4 deletions src/main/java/me/diademiemi/lineation/line/Line.java
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ public String getBlockSequenceString() {
int i = 1;
for (String s : blockSequence) {
if (i > 1) {
blockSequenceString.append(",");
blockSequenceString.append(", ");
}
blockSequenceString.append(s);
i++;
Expand All @@ -843,10 +843,26 @@ public String getBlockSequenceString() {
* Sets this lines block sequence
*
* @param blockSequence Comma seperated list of block names
*
* @return If action was successful
*/
public void setBlockSequence(String blockSequence) {
this.blockSequence = new ArrayList<String>(Arrays.asList(blockSequence.split("\\s*,\\s*")));
}
public boolean setBlockSequence(String blockSequence) {

if (LineTools.validateBlocks(blockSequence)){

if (this.type == "finish") {
this.blockSequence = new ArrayList<String>(Arrays.asList(blockSequence.split("\\s*,\\s*")[0]));
} else {
this.blockSequence = new ArrayList<String>(Arrays.asList(blockSequence.split("\\s*,\\s*")));
}

} else {
return false;
}

return true;

}

/**
* Check if this player is in this area
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/me/diademiemi/lineation/line/LineTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.command.CommandSender;
import org.bukkit.Material;
import org.bukkit.World;

import me.diademiemi.lineation.Lineation;
import me.diademiemi.lineation.Message;
import me.diademiemi.lineation.Config;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -422,6 +424,27 @@ public static void stopLine(Line line) {
}
}

/**
* Method to validate if block sequence is valid
*
* @param sequence String to validate
*
* @return Boolean of whether string is valid
*/
public static boolean validateBlocks(String sequence){
ArrayList<String> blockList = new ArrayList<String>(Arrays.asList(sequence.split("\\s*,\\s*")));

for (String s : blockList) {
try {
Material.valueOf(s.toUpperCase());
} catch (IllegalArgumentException ex) {
return false;
}
}

return true;
}

/**
* Method to replace blocks in a given area with a given EditSession with names of blocks to set
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ ERROR_SEE_HELP: '&7Missing arguments! Check $COMMAND$'
ERROR_UNKNOWN_LINE: '&7Unknown line: &f&l$LINE$'
ERROR_NULL_AREA: '&7Make a cuboid selection with WorldEdit first!'
ERROR_INVALID_NAME: '&7This name is not allowed!'
ERROR_INVALID_BLOCK: '&7Invalid blocks! One or more of these blocks are unknown!'
ERROR_NOT_START: '&7The line &f&l$LINE$&r&7 is not a start line!'
ERROR_NOT_FINISH: '&7The line &f&l$LINE$&r&7 is not a finish line!'
ERROR_NO_CHECKPOINT: '&7The line &f&l$LINE$&r&7 has no checkpoints! This is required for lines with multiple laps to prevent players from cheating.'
Expand Down

0 comments on commit b94e4e4

Please sign in to comment.