Last active
April 14, 2016 20:11
-
-
Save jamierocks/d6c210fd363c8507e20c4eba7dc4f572 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.jamierocks.sponge.hack.scoreboard; | |
import uk.jamierocks.sponge.hack.util.Wrapper; | |
import com.google.common.collect.Sets; | |
import org.spongepowered.api.scoreboard.Score; | |
import org.spongepowered.api.scoreboard.Team; | |
import org.spongepowered.api.text.Text; | |
public class HackScore extends Wrapper<Score> { | |
private Team fakeTeam; | |
public HackScore(Score handle) { | |
super(handle); | |
this.fakeTeam = Team.builder() | |
.name(handle.getName() + "-team") | |
.displayName(handle.getName().toBuilder().append(Text.of("Team")).build()) | |
.members(Sets.newHashSet(handle.getName())) | |
.build(); | |
} | |
public Team getFakeTeam() { | |
return this.fakeTeam; | |
} | |
public void setDisplayName(Text text) { | |
this.fakeTeam.setSuffix(text); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.jamierocks.sponge.hack.scoreboard; | |
import uk.jamierocks.sponge.hack.util.Wrapper; | |
import org.spongepowered.api.scoreboard.Scoreboard; | |
import org.spongepowered.api.scoreboard.critieria.Criteria; | |
import org.spongepowered.api.scoreboard.displayslot.DisplaySlot; | |
import org.spongepowered.api.scoreboard.displayslot.DisplaySlots; | |
import org.spongepowered.api.scoreboard.objective.Objective; | |
import org.spongepowered.api.text.Text; | |
import org.spongepowered.api.text.format.TextColors; | |
public class HackScoreboard extends Wrapper<Scoreboard> { | |
private static final Objective OBJECTIVE = Objective.builder() | |
.name("hack-obj") | |
.displayName(Text.builder().append(Text.of("Hack")).color(TextColors.DARK_BLUE).build()) | |
.criterion(Criteria.DUMMY) | |
.build(); | |
private int lastPosition = 15; | |
public HackScoreboard() { | |
super(Scoreboard.builder().build()); | |
this.addDivider(Text.of(TextColors.RESET)); | |
this.getHandle().addObjective(OBJECTIVE); | |
this.getHandle().updateDisplaySlot(OBJECTIVE, DisplaySlots.SIDEBAR); | |
} | |
/** | |
* Gets the objective from the given {@link DisplaySlot}. | |
* | |
* @param slot The display slot. | |
* @return An objective is their is one for that slot, or {@code null} otherwise. | |
*/ | |
public Objective getObjective(DisplaySlot slot) { | |
if (this.getHandle().getObjective(slot).isPresent()) { | |
return this.getHandle().getObjective(slot).get(); | |
} | |
return null; | |
} | |
public void addScore(HackScore hackScore) { | |
hackScore.getHandle().setScore(this.getNextPosition()); | |
this.getHandle().registerTeam(hackScore.getFakeTeam()); | |
} | |
public void addDivider(Text text) { | |
OBJECTIVE.getOrCreateScore(text).setScore(this.getNextPosition()); | |
} | |
public int getNextPosition() { | |
return this.lastPosition--; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uk.jamierocks.sponge.hack.util; | |
public abstract class Wrapper<T> { | |
private final T handle; | |
public Wrapper(final T handle) { | |
this.handle = handle; | |
} | |
public T getHandle() { | |
return this.handle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment