Hello Sponge contributors,
So I have tried to create a test sponge scoreboard with this code, but it didnt work(Do i have to register it? And if yes where?)
@Listener
public void onEntity(ClientConnectionEvent.Join e) {
Player p = e.getTargetEntity();
Scoreboard sb = Scoreboard.builder().build();
Objective obj = Objective.builder().criterion(Criteria.DUMMY).displayName(Text.of("MSB")).name("MainSideBoard").build();
java.util.Optional<Score> s = obj.getScore(Text.of("Online:"));
if(s.isPresent()){
Score s1 = s.get();
s1.setScore(1);
}
sb.addObjective(obj);
sb.updateDisplaySlot(obj, DisplaySlots.SIDEBAR);
p.setScoreboard(sb);
}
This gives me no ERRORS, but without the Optional it would give me a "java.util.NoSuchElementException: No value present"
. Did I do something wrong?
The scoreboard does not show up, it only gives an error without the Optinal, but the optinal just filters the NoSuch… thing out. Any ideas?(an example code would also be helpful)