0
if (Bukkit.getOnlinePlayers().size() >= 5) {
                if (Tasks.RC_TIME >= 3) {
                    Tasks.RC_TIME = 0;
                    int x = (int)(Main.ARENA_MID.getX() + Math.random() * Main.ARENA_RADIUS * 0.75D * ((Math.random() < 0.5D) ? -1 : true));
                    int z = (int)(Main.ARENA_MID.getZ() + Math.random() * Main.ARENA_RADIUS * 0.75D * ((Math.random() < 0.5D) ? -1 : true));
                    double r = Math.random();
                    if (r < 0.25D) {
                        RareCrate.activate(new Location(Bukkit.getWorld("world"), x, Bukkit.getWorld("world").getHighestBlockYAt(x, z), z));
                        Bukkit.broadcastMessage(ChatColor.GOLD + "A crate has been discovered at x:" + x + ", z:" + z + "! Collecting it will credit you crates!");
                    } else if (r >= 0.25D && r <= 0.5D) {
                        RareLevel.activate(new Location(Bukkit.getWorld("world"), x, Bukkit.getWorld("world").getHighestBlockYAt(x, z), z));
                        Bukkit.broadcastMessage(ChatColor.AQUA + "A Level Powerup has been discovered at x:" + x + ", z:" + z + "! Collecting it will credit you 1 level!");
                    } else if (r >= 0.5D) {
                        RareCoin.activate(new Location(Bukkit.getWorld("world"), x, Bukkit.getWorld("world").getHighestBlockYAt(x, z), z));
                        Bukkit.broadcastMessage(ChatColor.YELLOW + "A rare coin has been discovered at x:" + x + ", z:" + z + "! Collecting it will credit you up to 10000 coins!");
                    } 
                } 

Ive been updating a plugin for MC that someone else abandoned, and cannot figure out this. At the end of line 4: int x = (int)(Main.ARENA_MID.getX() + Math.random() * Main.ARENA_RADIUS * 0.75D * ((Math.random() < 0.5D) ? -1 : true)); most specifically the ? -1 : true and what that means?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    `(Math.random() < 0.5D) ? -1 : true` is an expression using the ternary operator, but it is bogus in that context, and questionable in any context. The type of the expression is a common supertype of the (possibly auto(un)boxed) types of the second and third operands, `-1` and `true`, and the only type that fits is `Object`. But `Object` cannot be unboxed to yield a suitable operand for the preceding `*` operator, so I would expect the compiler to reject the overall statement. It would make more sense if `true` were replaced with a number, maybe `1`. – John Bollinger Jan 12 '21 at 21:08
  • Another sign of low quality code: All those `D`s after decimals are redundant; as per the JLS decimal constants are compiled as `double` by default. – Bohemian Jan 12 '21 at 21:28
  • Please consider [`String.format()`](https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/String.html#format(java.lang.String,java.lang.Object...)) for string literal(s) + variable(s) concatenation. – Gerold Broser Jan 12 '21 at 21:42
  • is this decompiled code? maybe a `1` in the bytecode was incorrectly replaced with `true` in the generated source. – Clashsoft Jan 12 '21 at 22:03

0 Answers0