Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update the current code for cloudburst server
  • Loading branch information
Redned235 authored and lukeeey committed Sep 23, 2020
commit 441c97bf9176a323653adccc60423288c16d58bb
36 changes: 36 additions & 0 deletions src/main/java/org/cloudburstmc/server/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@
import org.cloudburstmc.server.registry.CommandRegistry;
import org.cloudburstmc.server.registry.EntityRegistry;
import org.cloudburstmc.server.registry.ItemRegistry;
import org.cloudburstmc.server.scoreboard.Scoreboard;
import org.cloudburstmc.server.scoreboard.impl.CloudburstScoreboard;
import org.cloudburstmc.server.utils.*;

import javax.annotation.Nullable;
import java.io.File;
import java.net.InetSocketAddress;
import java.util.*;
Expand Down Expand Up @@ -220,6 +223,8 @@ public class Player extends Human implements CommandSender, InventoryHolder, Chu

private final PlayerChunkManager chunkManager = new PlayerChunkManager(this);

private Scoreboard scoreboard;

public int packetsRecieved;

public long lastSkinChange;
Expand Down Expand Up @@ -2006,6 +2011,10 @@ public void close(TextContainer message, String reason, boolean notify) {
if (this.fishing != null) {
this.stopFishing(false);
}
if (this.scoreboard != null) {
((CloudburstScoreboard) this.scoreboard).getPlayers().remove(this);
this.scoreboard = null;
}
}

for (Player player : new ArrayList<>(this.server.getOnlinePlayers().values())) {
Expand Down Expand Up @@ -3342,6 +3351,33 @@ public boolean pickupEntity(Entity entity, boolean near) {
return false;
}

/**
* Gets the current {@link Scoreboard} of
* the player
*
* @return the current scoreboard of the player
*/
@Nullable
public Scoreboard getScoreboard() {
return this.scoreboard;
}

/**
* Sets the player's {@link Scoreboard} to the
* specified scoreboard
*
* @param scoreboard the scoreboard to set
*/
public void setScoreboard(@Nullable Scoreboard scoreboard) {
if (this.scoreboard != null) {
((CloudburstScoreboard) this.scoreboard).hide(this);
}
if (scoreboard != null) {
((CloudburstScoreboard) scoreboard).show(this);
}
this.scoreboard = scoreboard;
}

@Override
public String toString() {
return "Player(name=" + getName() + ")";
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/cloudburstmc/server/scoreboard/DisplayMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.cloudburstmc.server.scoreboard;

/**
* Represents where a {@link ScoreboardObjective} should be displayed
* on a {@link Scoreboard}.
*/
public enum DisplayMode {

/**
* Display mode that shows the objective
* in the player list.
*/
LIST,

/**
* Display mode that shows the objective
* ion the sidebar.
*/
SIDEBAR,

/**
* Display mode that shows the objective
* below the player's name.
*/
BELOWNAME
}
81 changes: 81 additions & 0 deletions src/main/java/org/cloudburstmc/server/scoreboard/Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.cloudburstmc.server.scoreboard;

import org.cloudburstmc.server.scoreboard.impl.CloudburstScore;

/**
* Represents a score for a {@link ScoreboardObjective}.
*/
public interface Score<T> {

/**
* Gets the {@link ScoreboardObjective} of
* this score
*
* @return the scoreboard objective of this score
*/
ScoreboardObjective getObjective();

/**
* Gets the amount
*
* @return the amount
*/
int getAmount();

/**
* Sets the amount
*
* @param value the amount
*/
void setAmount(int value);

/**
* Gets the name of this score
*
* @return the name of this score
*/
String getName();

/**
* Gets the type of score this is
*
* @return the type of score this is
*/
ScoreType<T> getScoreType();

/**
* Gets the value of this score
*
* @return the value of this score
*/
T getValue();

/**
* Sets the value of the score
*
* @param value the value of the score
*/
void setValue(T value);

/**
* Creates a new instance of a {@link ScoreBuilder}
*
* @param scoreType the score type
* @param <U> the value
* @return a new instance of a score builder
*/
static <U> ScoreBuilder<U> builder(ScoreType<U> scoreType) {
return CloudburstScore.providedBuilder(scoreType);
}

interface ScoreBuilder<T> {

ScoreBuilder<T> amount(int amount);

ScoreBuilder<T> name(String name);

ScoreBuilder<T> value(T value);

Score<T> build();
}
}
50 changes: 50 additions & 0 deletions src/main/java/org/cloudburstmc/server/scoreboard/ScoreType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.cloudburstmc.server.scoreboard;

import cn.nukkit.player.Player;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import org.cloudburstmc.server.entity.Entity;

/**
* Represents the score type for the
* {@link Score} in a {@link Scoreboard}.
*/
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ScoreType<T> {

/**
* A score type where the value is
* that of a player.
*/
public static final ScoreType<Player> PLAYER = new ScoreType<>("player", Player.class);

/**
* A score type where the value is
* that of an entity.
*/
public static final ScoreType<Entity> ENTITY = new ScoreType<>("entity", Entity.class);

/**
* A fake score type that does not
* require an entity or player.
*/
public static final ScoreType<String> FAKE = new ScoreType<>("fake", String.class);

private String name;
private Class<T> supportedType;

/**
* Gets the supported value type for
* this score type
*
* @return the supported value for this score type
*/
public Class<T> getSupportedType() {
return supportedType;
}

@Override
public String toString() {
return name;
}
}
58 changes: 58 additions & 0 deletions src/main/java/org/cloudburstmc/server/scoreboard/Scoreboard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.cloudburstmc.server.scoreboard;

import org.cloudburstmc.server.player.Player;
import org.cloudburstmc.server.scoreboard.impl.CloudburstScoreboard;

import javax.annotation.Nullable;
import java.util.Collection;

/**
* Represents a scoreboard in the game, which can contain
* various information and be used to display data for players.
*/
public interface Scoreboard {

/**
* Gets the {@link ScoreboardObjective} with the specified name
*
* @param objectiveName the name of the objective
* @return the objective with the specified name
*/
@Nullable
ScoreboardObjective getObjective(String objectiveName);

/**
* Registers a new {@link ScoreboardObjective} to the scoreboard
* @param objective the objective
*/
void registerObjective(ScoreboardObjective objective);

/**
* Deregisters a {@link ScoreboardObjective} from the scoreboard.
*
* @param name the name of the objective
*/
void deregisterObjective(String name);

/**
* Creates a new instance of a {@link ScoreboardBuilder}
*
* @return a new instance of a scoreboard builder
*/
static ScoreboardBuilder builder() {
return CloudburstScoreboard.providedBuilder();
}

interface ScoreboardBuilder {

ScoreboardBuilder objectives(ScoreboardObjective... objectives);

ScoreboardBuilder players(Player... players);

default ScoreboardBuilder players(Collection<Player> players) {
return this.players(players.toArray(new Player[0]));
}

Scoreboard build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.cloudburstmc.server.scoreboard;

/**
* The criterion for a {@link ScoreboardObjective}.
*/
public enum ScoreboardCriteria {

/**
* Dummy scoreboard criterion.
*/
DUMMY
}
Loading