Ist dieser Code für ein einfaches Bukkit Plugin gut/richtig?

Und wenn nein: Was ist falsch und wie muss ich es verbessern?

package main.Bukkit.plugin.mcp;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.mojang.brigadier.Command;

public class Plugin extends JavaPlugin {
   public String PluginName=this.getDescription().getName();
   public String PluginVers=this.getDescription().getVersion();

   @Override
   public void onEnable() {
      System.out.println(" ");
      System.out.println("["+ChatColor.DARK_GRAY+"] Plugin gestartet! Version: "+PluginVers);
      System.out.println(" ");
   }

   @Override
   public void onDisable() {
      System.out.println(" ");
      System.out.println("["+PluginName+ChatColor.DARK_GRAY+"] Plugin gestartet! Version: "+PluginVers);
      System.out.println(" ");
   }

   @SuppressWarnings("rawtypes")
   public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

      Player player=null;
       if(sender instanceof Player) {
          player=(Player) sender;
       }

      if(((CommandSender) cmd).getName().equalsIgnoreCase("hallo")) {
         if(player!=null) {
            player.sendMessage("Hallo, "+player.getDisplayName());
            return true;
         } 
      }

      return false;
   }
}
...zur Frage

mach aus

Player player=null;
       if(sender instanceof Player) {
          player=(Player) sender;
       }

das

       if(!(sender instanceof Player)) {
          return;
       }
       Player player = (Player) sender;
...zur Antwort
fun main() {
    val array = Array(360) { BooleanArray(6284) }

    val t1 = measureTimeMillis {
        for(i in 0..359) {
            for(distanceIter in 0..6283) {
                val distance = distanceIter / 1000.0
                array[i][distanceIter] = sin((Math.PI * (ln(1 - (i - 360 + 3.5) * (1 - 0.6)) / ln(0.6))) + distance) > 0
            }
        }
    }

    val t2 = measureTimeMillis {
        val C = Math.PI / ln(0.6)
        val D = ln(0.4)

        for(i in 0..359) {
            for(distanceIter in 0..6283) {
                val distance = distanceIter / 1000.0
                var calc = (distance + C * (ln(-i + 359.0) + D)) % (2 * Math.PI)

                while(calc < 0)
                    calc += 2 * Math.PI

                array[i][distanceIter] = calc < Math.PI
            }
        }
    }

    println("T1: $t1")
    println("T2: $t2")
}

Ergebnis:

T1: 152
T2: 28
ca. 5 mal so schnell

Und so könnts man im Array speichern:

fun main() {
    val array = Array(360) { BooleanArray(628301) }

    val t1 = measureTimeMillis {
        for(i in 0..359) {
            for(distanceIter in 0..628300) {
                val distance = distanceIter / 10000.0
                var calc = (distance + C * (ln(-i + 359.0) + D)) % (2 * Math.PI)

                while(calc < 0)
                    calc += 2 * Math.PI

                array[i][distanceIter] = calc < Math.PI
            }
        }
    }

    fun get(distance: Double, i: Int) {
        val shouldBe = array[i][round(distance * 10000).toInt()]
        val got = array[i][round(((distance * 10000) % (2 * Math.PI * 10000))).toInt()]

        if(shouldBe != got) {
            println("$shouldBe != $got (i=$i; d=$distance; 1=${round(distance * 1000).toInt()}; 2=${round(((distance * 1000) % (2 * Math.PI * 1000))).toInt()})")
        }
    }

    for(i in 0..359) {
        for(distanceIter in 0..62830) {
            val distance = distanceIter / 1000.0
            get(distance, i)
        }
    }
}

Und so viele Fehler gibts:

false != true (i=2; d=30.513; 1=30513; 2=5380)
false != true (i=5; d=8.47; 1=8470; 2=2187)
false != true (i=6; d=21.019; 1=21019; 2=2169)
true != false (i=9; d=55.524; 1=55524; 2=5259)
false != true (i=10; d=58.648; 1=58648; 2=2099)
false != true (i=11; d=30.356; 1=30356; 2=5223)
true != false (i=13; d=11.471; 1=11471; 2=5188)
false != true (i=14; d=20.878; 1=20878; 2=2028)
true != false (i=17; d=61.665; 1=61665; 2=5116)
false != true (i=18; d=30.231; 1=30231; 2=5098)
false != true (i=18; d=45.939; 1=45939; 2=1957)
false != true (i=26; d=30.085; 1=30085; 2=4952)
false != true (i=43; d=20.338; 1=20338; 2=1488)
true != false (i=47; d=32.826; 1=32826; 2=1410)
false != true (i=50; d=29.625; 1=29625; 2=4492)
true != false (i=51; d=61.021; 1=61021; 2=4472)
true != false (i=52; d=61.001; 1=61001; 2=4452)
false != true (i=53; d=29.565; 1=29565; 2=4432)
true != false (i=56; d=32.646; 1=32646; 2=1230)
false != true (i=63; d=57.635; 1=57635; 2=1086)
false != true (i=64; d=51.331; 1=51331; 2=1066)
false != true (i=66; d=29.298; 1=29298; 2=4165)
true != false (i=71; d=22.909; 1=22909; 2=4059)
false != true (i=72; d=19.746; 1=19746; 2=896)
false != true (i=74; d=19.703; 1=19703; 2=853)
false != true (i=75; d=7.115; 1=7115; 2=832)
true != false (i=75; d=22.823; 1=22823; 2=3973)
false != true (i=78; d=35.324; 1=35324; 2=3908)
false != true (i=81; d=35.258; 1=35258; 2=3842)
false != true (i=82; d=57.227; 1=57227; 2=678)
true != false (i=83; d=32.072; 1=32072; 2=656)
true != false (i=87; d=25.699; 1=25699; 2=566)
false != true (i=87; d=41.407; 1=41407; 2=3708)
true != false (i=89; d=53.928; 1=53928; 2=3663)
true != false (i=90; d=31.914; 1=31914; 2=498)
false != true (i=95; d=28.657; 1=28657; 2=3524)
false != true (i=95; d=44.365; 1=44365; 2=383)
false != true (i=98; d=19.162; 1=19162; 2=312)
false != true (i=99; d=6.572; 1=6572; 2=289)
true != false (i=100; d=47.389; 1=47389; 2=3407)
false != true (i=101; d=56.79; 1=56790; 2=241)
false != true (i=102; d=19.067; 1=19067; 2=217)
true != false (i=105; d=9.57; 1=9570; 2=3287)
false != true (i=107; d=12.663; 1=12663; 2=97)
true != false (i=118; d=31.238; 1=31238; 2=6105)
true != false (i=121; d=31.161; 1=31161; 2=6028)
true != false (i=125; d=21.632; 1=21632; 2=2782)
false != true (i=126; d=34.172; 1=34172; 2=2756)
true != false (i=131; d=30.897; 1=30897; 2=5764)
true != false (i=133; d=37.126; 1=37126; 2=5710)
false != true (i=134; d=11.966; 1=11966; 2=5683)
false != true (i=135; d=24.505; 1=24505; 2=5655)
true != false (i=136; d=59.035; 1=59035; 2=2486)
true != false (i=137; d=30.733; 1=30733; 2=5600)
false != true (i=139; d=18.111; 1=18111; 2=5545)
false != true (i=141; d=24.338; 1=24338; 2=5488)
true != false (i=144; d=14.828; 1=14828; 2=2262)
false != true (i=149; d=55.524; 1=55524; 2=5259)
true != false (i=152; d=20.878; 1=20878; 2=2028)
false != true (i=154; d=61.659; 1=61659; 2=5110)
true != false (i=156; d=20.758; 1=20758; 2=1908)
false != true (i=160; d=17.494; 1=17494; 2=4928)
true != false (i=163; d=14.259; 1=14259; 2=1693)
true != false (i=168; d=29.808; 1=29808; 2=4675)
true != false (i=171; d=57.985; 1=57985; 2=1436)
true != false (i=172; d=51.669; 1=51669; 2=1404)
false != true (i=177; d=23.228; 1=23228; 2=4378)
true != false (i=180; d=13.701; 1=13701; 2=1135)
true != false (i=182; d=51.331; 1=51331; 2=1066)
true != false (i=183; d=29.305; 1=29305; 2=4172)
false != true (i=187; d=26.022; 1=26022; 2=889)
true != false (i=188; d=19.703; 1=19703; 2=853)
false != true (i=193; d=54.078; 1=54078; 2=3813)
false != true (i=197; d=53.928; 1=53928; 2=3663)
false != true (i=198; d=22.474; 1=22474; 2=3624)
true != false (i=199; d=50.71; 1=50710; 2=445)
true != false (i=203; d=6.572; 1=6572; 2=289)
false != true (i=214; d=31.255; 1=31255; 2=6122)
true != false (i=216; d=28.028; 1=28028; 2=2895)
false != true (i=223; d=15.153; 1=15153; 2=2587)
true != false (i=224; d=11.966; 1=11966; 2=5683)
false != true (i=225; d=37.053; 1=37053; 2=5637)
false != true (i=226; d=21.299; 1=21299; 2=2449)
true != false (i=227; d=18.111; 1=18111; 2=5545)
false != true (i=230; d=14.828; 1=14828; 2=2262)
true != false (i=233; d=55.524; 1=55524; 2=5259)
true != false (i=234; d=55.475; 1=55475; 2=5210)
false != true (i=235; d=52.284; 1=52284; 2=2019)
true != false (i=236; d=61.659; 1=61659; 2=5110)
false != true (i=237; d=52.184; 1=52184; 2=1919)
true != false (i=238; d=39.567; 1=39567; 2=1868)
false != true (i=241; d=36.271; 1=36271; 2=4855)
true != false (i=244; d=48.679; 1=48679; 2=4697)
true != false (i=246; d=10.872; 1=10872; 2=4589)
true != false (i=249; d=60.972; 1=60972; 2=4423)
false != true (i=252; d=29.386; 1=29386; 2=4253)
true != false (i=253; d=54.461; 1=54461; 2=4196)
false != true (i=261; d=57.12; 1=57120; 2=571)
false != true (i=263; d=50.71; 1=50710; 2=445)
true != false (i=265; d=16.023; 1=16023; 2=3457)
true != false (i=272; d=31.255; 1=31255; 2=6122)
true != false (i=277; d=30.891; 1=30891; 2=5758)
false != true (i=278; d=11.966; 1=11966; 2=5683)
false != true (i=279; d=24.456; 1=24456; 2=5606)
false != true (i=284; d=55.475; 1=55475; 2=5210)
true != false (i=286; d=30.176; 1=30176; 2=5043)
false != true (i=288; d=23.722; 1=23722; 2=4872)
true != false (i=289; d=14.21; 1=14210; 2=1644)
false != true (i=290; d=48.679; 1=48679; 2=4697)
true != false (i=291; d=58.014; 1=58014; 2=1465)
false != true (i=292; d=10.799; 1=10799; 2=4516)
false != true (i=293; d=60.972; 1=60972; 2=4423)
false != true (i=294; d=23.179; 1=23179; 2=4329)
true != false (i=295; d=35.65; 1=35650; 2=4234)
false != true (i=303; d=25.404; 1=25404; 2=271)
true != false (i=307; d=34.373; 1=34373; 2=2957)
true != false (i=311; d=24.456; 1=24456; 2=5606)
true != false (i=313; d=33.619; 1=33619; 2=2203)
true != false (i=314; d=55.475; 1=55475; 2=5210)
false != true (i=315; d=30.204; 1=30204; 2=5071)
false != true (i=316; d=58.337; 1=58337; 2=1788)
false != true (i=317; d=14.21; 1=14210; 2=1644)
true != false (i=320; d=23.179; 1=23179; 2=4329)
true != false (i=321; d=32.444; 1=32444; 2=1028)
false != true (i=324; d=57.071; 1=57071; 2=522)
false != true (i=332; d=55.475; 1=55475; 2=5210)
true != false (i=333; d=8.119; 1=8119; 2=1836)
true != false (i=337; d=19.658; 1=19658; 2=808)
true != false (i=338; d=57.071; 1=57071; 2=522)
false != true (i=343; d=52.257; 1=52257; 2=1992)
true != false (i=345; d=26.303; 1=26303; 2=1170)
false != true (i=348; d=62.519; 1=62519; 2=5970)
true != false (i=354; d=26.254; 1=26254; 2=1121)
false != true (i=356; d=26.254; 1=26254; 2=1121)
...zur Antwort

Erstmal müssen wir aufpassen, denn der Math.log ist in der Welt der Mathematik meistens der natürliche Logarithmus ln

C=pi/ln(0,6) => negativ
d + C * ln(-0,4i + 143,6) > 0

ln(-0,4i + 143,6) = 0
i = 356,5

ln(-0,4*359 + 143,6)=ln(0) // geht nicht, so btw
ln(-0,4*0 + 143,6)=ln(143,6) // maximaler wert
ln(-0,4*357 + 143,6) // negativ
ln(-0,4*356 + 143,6) // positiv


if(i > 355) {
  d + positiv > 0 // da d immer positiv, immer true
} else {
  d + negativ > 0
}

Also final:
C = Math.PI / Math.log(0.6);
MAX = -C * Math.log(143.6);

public boolean get(double d, int i) {
 return (i > 355 && d > 0) || d > MAX || d + C * Math.log(-0,4i + 143,6) > 0
}

Habs aber nicht ausprobiert, aber vlt hilft dir das

...zur Antwort

Zu schlechte Auflösung

...zur Antwort

Unendlich RAM ungleich unendlich Spieler

CPU macht auch viel aus bei hohen Spielerzahlen

...zur Antwort

Anzahl Möglichkeiten pro Wurf: 6*6=36

Wahrscheinlichkeit Pasche pro Wurf: 6/36 = 1/6

Anzahl = 200 / 6 = 33,333...

...zur Antwort
Map<Pos, Color>
class Pos(val x, val y)

oder

List<PosColor>
class PosColor(val x, val y, val color)

void set(PosColor pc) {
  val index = list.first { it.x == pc.x && it.y == pc.y}
  if(index == -1) list.add(pc);
  else list.set(index, pc);
}

oder so ähnlich

...zur Antwort

JavaFX oder Swing?

...zur Antwort

Mit verschiedenen Salts arbeiten und hashen?

...zur Antwort

Dafür benutzt man Lexer

...zur Antwort

https://github.com/Bukkit/mc-dev/blob/c1627dc9cc7505581993eb0fa15597cb36e94244/net/minecraft/server/WorldGenVillageWell.java

https://github.com/Bukkit/mc-dev/blob/c1627dc9cc7505581993eb0fa15597cb36e94244/net/minecraft/server/WorldGenVillage.java

https://github.com/skps2010/VillageGenerator/blob/master/VillageGenerator/src/game/check/Create_1_13.java

finds selbst heraus

...zur Antwort

Von vollen Endlosschleifen habe ich noch nicht gehört, nur so was:

while(!exit) {
  gameloop();
  if(closeRequest) { exit = true }
}

Falls du nur while(true) meinst, das benutzt man auch manchmal:

do {
  String s = readNextLine();
  if(s == null) break;
  list.add(s);
} while(true);
...zur Antwort