From 25b9c491c336886073d195161b4afeec30068618 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Fri, 23 Jul 2021 08:55:53 -0400 Subject: [PATCH] Fix bitwise calculator --- .../iris/core/command/CommandIrisBitwise.java | 92 +++++++++++-------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/command/CommandIrisBitwise.java b/src/main/java/com/volmit/iris/core/command/CommandIrisBitwise.java index 23c7ff576..dff392894 100644 --- a/src/main/java/com/volmit/iris/core/command/CommandIrisBitwise.java +++ b/src/main/java/com/volmit/iris/core/command/CommandIrisBitwise.java @@ -48,56 +48,70 @@ public class CommandIrisBitwise extends MortarCommand { sender.sendMessage("/iris bw " + getArgsUsage()); } - if(args[0].contains(",")) + try { - KList r = new KList<>(); - - for(String i : args[0].split("\\Q,\\E")) + if(args[0].contains(",")) { - int a = Integer.valueOf(i); + KList r = new KList<>(); + + for(String i : args[0].split("\\Q,\\E")) + { + int a = Integer.parseInt(i); + String op = args[1]; + int b = Integer.parseInt(args[2]); + int v = 0; + + 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 -> { + { + sender.sendMessage("Error Invalid operation"); + return true; + } + } + } + ; + + r.add(v); + sender.sendMessage("Result: " + r.toString(",")); + } + } + + else + { + 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) - { - 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"); - }; - }; + 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 -> { + { + sender.sendMessage("Error Invalid operation"); + return true; + } + } + } + ; - r.add(v); - sender.sendMessage("Result: " + r.toString(",")); + sender.sendMessage("Result: " + v); } } - else + catch(Throwable ignored) { - int a = Integer.valueOf(args[0]); - String op = args[1]; - int b = Integer.valueOf(args[2]); - int v = 0; - 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: { - sender.sendMessage("Error Invalid operation"); - }; - }; - - sender.sendMessage("Result: " + v); } return true;