Fix bitwise calculator

This commit is contained in:
Daniel Mills 2021-07-23 08:55:53 -04:00
parent 8f1b48b0ab
commit 25b9c491c3

View File

@ -48,29 +48,34 @@ public class CommandIrisBitwise extends MortarCommand {
sender.sendMessage("/iris bw " + getArgsUsage());
}
try
{
if(args[0].contains(","))
{
KList<Integer> r = new KList<>();
for(String i : args[0].split("\\Q,\\E"))
{
int a = Integer.valueOf(i);
int a = Integer.parseInt(i);
String op = args[1];
int b = Integer.valueOf(args[2]);
int b = Integer.parseInt(args[2]);
int v = 0;
switch(op)
switch (op) {
case "|" -> v = a | b;
case "&" -> v = a & b;
case "^" -> v = a ^ b;
case "%" -> v = a % b;
case ">>" -> v = a >> b;
case "<<" -> v = a << b;
default -> {
{
case "|": v = a | b;
case "&": v = a & b;
case "^": v = a ^ b;
case "%": v = a ^ b;
case ">>": v = a >> b;
case "<<": v = a << b;
default: {
sender.sendMessage("Error Invalid operation");
};
};
return true;
}
}
}
;
r.add(v);
sender.sendMessage("Result: " + r.toString(","));
@ -79,26 +84,35 @@ public class CommandIrisBitwise extends MortarCommand {
else
{
int a = Integer.valueOf(args[0]);
int a = Integer.parseInt(args[0]);
String op = args[1];
int b = Integer.valueOf(args[2]);
int b = Integer.parseInt(args[2]);
int v = 0;
switch(op)
switch (op) {
case "|" -> v = a | b;
case "&" -> v = a & b;
case "^" -> v = a ^ b;
case "%" -> v = a % b;
case ">>" -> v = a >> b;
case "<<" -> v = a << b;
default -> {
{
case "|": v = a | b;
case "&": v = a & b;
case "^": v = a ^ b;
case "%": v = a ^ b;
case ">>": v = a >> b;
case "<<": v = a << b;
default: {
sender.sendMessage("Error Invalid operation");
};
};
return true;
}
}
}
;
sender.sendMessage("Result: " + v);
}
}
catch(Throwable ignored)
{
}
return true;
}