Skip to content

Commit

Permalink
Version 3.9.7.9:
Browse files Browse the repository at this point in the history
Fixes:
* Fix for Spigot servers and join lag caused by Scoreboards
  • Loading branch information
alkarinv committed Jun 26, 2014
1 parent a89ce2d commit 9dbca30
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 52 deletions.
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>mc.alk</groupId>
<artifactId>BattleArena</artifactId>
<packaging>jar</packaging>
<version>3.9.7.8.1</version>
<version>3.9.7.9</version>
<name>BattleArena</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -40,6 +40,12 @@
<!-- Dependencies -->
<dependencies>
<!-- Dependencies that have maven repos -->
<dependency>
<groupId>mc.alk</groupId>
<artifactId>BattleProfiler</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>mc.alk</groupId>
<artifactId>BattlePluginUpdater</artifactId>
Expand All @@ -55,7 +61,7 @@
<dependency>
<groupId>mc.alk</groupId>
<artifactId>BattleScoreboardAPI</artifactId>
<version>1.1.8.4</version>
<version>1.1.8.4.2</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -253,6 +259,7 @@
<artifact>mc.alk:BattleScoreboardAPI</artifact>
<includes>
<include>mc/alk/scoreboardapi/**</include>
<include>mc/alk/profiling/**</include>
</includes>

</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ public TeamJoinResult(TeamJoinStatus status, int remaining, ArenaTeam team){
public int getRemaining(){return remaining;}
}

public AbstractJoinHandler(MatchParams params, Competition competition) {
public AbstractJoinHandler(MatchParams params, Competition competition, List<ArenaTeam> teams) {
this.matchParams = params;
this.minTeams = params.getMinTeams();
this.maxTeams = params.getMaxTeams();

setCompetition(competition);
if (Defaults.USE_SCOREBOARD && SAPI.hasBukkitScoreboard())
initWaitingScoreboard();
initWaitingScoreboard(teams);
}

private void initWaitingScoreboard() {
private void initWaitingScoreboard(List<ArenaTeam> startingTeams) {
List<ArenaTeam> teams = new ArrayList<ArenaTeam>();
try {
if (maxTeams <= 16) {
Expand All @@ -118,7 +118,7 @@ private void initWaitingScoreboard() {
return;
}
}
}catch(Throwable e) {
} catch (Throwable e) {
Log.printStackTrace(e);
}
scoreboard = new CutoffScoreboard(matchParams, teams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import mc.alk.arena.objects.teams.TeamFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class AddToLeastFullTeam extends AbstractJoinHandler {

public AddToLeastFullTeam(MatchParams params, Competition competition, Collection<ArenaTeam> newTeams)
public AddToLeastFullTeam(MatchParams params, Competition competition, List<ArenaTeam> newTeams)
throws NeverWouldJoinException{
super(params,competition);
super(params,competition, newTeams);
if (minTeams == ArenaSize.MAX || maxTeams == ArenaSize.MAX)
throw new NeverWouldJoinException("If you add players by adding them to the next team in the list, there must be a finite number of players");
/// Lets add in all our teams first
Expand Down
5 changes: 3 additions & 2 deletions src/java/mc/alk/arena/controllers/joining/BinPackAdd.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import mc.alk.arena.objects.teams.TeamFactory;

import java.util.Collection;
import java.util.List;

/**
* When there is an infinite number of teams
Expand All @@ -18,9 +19,9 @@
public class BinPackAdd extends AbstractJoinHandler {
boolean full = false;

public BinPackAdd(MatchParams params, Competition competition, Collection<ArenaTeam> newTeams)
public BinPackAdd(MatchParams params, Competition competition, List<ArenaTeam> newTeams)
throws NeverWouldJoinException {
super(params, competition);
super(params, competition, newTeams);
if (newTeams != null){
for (ArenaTeam at : newTeams) {
addTeam(at);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import mc.alk.arena.objects.exceptions.NeverWouldJoinException;
import mc.alk.arena.objects.teams.ArenaTeam;

import java.util.Collection;
import java.util.List;

public class TeamJoinFactory {

Expand All @@ -18,13 +18,13 @@ public static AbstractJoinHandler createTeamJoinHandler(MatchParams params, Comp
return createTeamJoinHandler(params,competition,null);
}

public static AbstractJoinHandler createTeamJoinHandler(MatchParams params, Collection<ArenaTeam> teams) throws NeverWouldJoinException {
public static AbstractJoinHandler createTeamJoinHandler(MatchParams params, List<ArenaTeam> teams) throws NeverWouldJoinException {
AbstractJoinHandler as = createTeamJoinHandler(params, null, teams);
return as;
}

public static AbstractJoinHandler createTeamJoinHandler(MatchParams params, Competition competition,
Collection<ArenaTeam> teams) throws NeverWouldJoinException {
List<ArenaTeam> teams) throws NeverWouldJoinException {
if (params.getMaxTeams() <= Defaults.MAX_TEAMS ){
return new AddToLeastFullTeam(params, competition, teams); /// lets try and add players to all players first
} else { /// finite team size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import mc.alk.scoreboardapi.api.SEntry;
import mc.alk.scoreboardapi.api.STeam;
import mc.alk.scoreboardapi.scoreboard.SAPIDisplaySlot;
import org.bukkit.Bukkit;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -45,6 +44,7 @@ public CutoffScoreboard(MatchParams params, List<ArenaTeam> teams) {
ppteam = 15 / maxTeams;
}
for (int i = 0; i <maxTeams && count < 15; i++) {
// Log.debug("&4i = " + i);
ArenaTeam team = i < teams.size() ? teams.get(i) : TeamFactory.createCompositeTeam(i, params);
team.setIDString(String.valueOf(team.getIndex()));
STeam t = scoreboard.addTeam(team);
Expand Down Expand Up @@ -116,7 +116,7 @@ private void addPlaceholder(ArenaTeam team, STeam t, boolean optionalTeam) {
String dis = "- " + name + " -" + team.getTeamChatColor() + TeamUtil.getTeamChatColor(index);
SEntry e = scoreboard.getEntry(dis);
if (e == null) {
e = scoreboard.createEntry(Bukkit.getOfflinePlayer(dis), dis);
e = scoreboard.createEntry(OfflinePlayerTeams.getOfflinePlayer(dis), dis);
ao.addEntry(e, points);
} else {
ao.setPoints(e, points);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import mc.alk.scoreboardapi.api.SEntry;
import mc.alk.scoreboardapi.api.STeam;
import mc.alk.scoreboardapi.scoreboard.SAPIDisplaySlot;
import org.bukkit.Bukkit;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
Expand All @@ -32,22 +32,28 @@ public class FullScoreboard implements WaitingScoreboard {
ArenaObjective ao;
final int minTeams;
Countdown countdown;


public FullScoreboard(MatchParams params, List<ArenaTeam> teams) {
scoreboard = ScoreboardFactory.createScoreboard(String.valueOf(this.hashCode()), params);
ao = scoreboard.createObjective("waiting",
"Queue Players", "&6Waiting Players", SAPIDisplaySlot.SIDEBAR, 100);
ao.setDisplayTeams(false);
minTeams = params.getMinTeams();
int maxTeams = params.getMaxTeams();
// HashMap<ArenaTeam, STeam> teamMap = new HashMap<ArenaTeam, STeam>();
List<ArenaTeam> ateams = new ArrayList<ArenaTeam>();
List<STeam> steams = new ArrayList<STeam>();
for (int i = 0; i < maxTeams; i++) {
ArenaTeam team = i < teams.size() ? teams.get(i) : TeamFactory.createCompositeTeam(i, params);

team.setIDString(String.valueOf(team.getIndex()));
STeam t = scoreboard.addTeam(team);
for (int j = 0; j < team.getMaxPlayers(); j++) {
addPlaceholder(team, t, i >= minTeams);
}
// teamMap.put(team, t);
steams.add(t);
ateams.add(team);
}
addPlaceholders(ateams, steams, minTeams); /// half
if (params.getForceStartTime() >0 &&
params.getForceStartTime() != ArenaSize.MAX
&& !params.getMaxPlayers().equals(params.getMinPlayers())
Expand All @@ -56,50 +62,78 @@ public FullScoreboard(MatchParams params, List<ArenaTeam> teams) {
}
}

private void addPlaceholders(List<ArenaTeam> ateams, List<STeam> steams, int minTeams) {
List<SEntry> es = new ArrayList<SEntry>();
List<Integer> points = new ArrayList<Integer>();
for (int i=0;i < ateams.size();i++) {
ArenaTeam at = ateams.get(i);
STeam st = steams.get(i);
for (int j = 0; j < ateams.get(i).getMaxPlayers(); j++) {
TempEntry te = createEntry(at, st, j >= minTeams);
SEntry e = scoreboard.getEntry(te.name);
if (e == null) {
e = scoreboard.createEntry(OfflinePlayerTeams.getOfflinePlayer(te.name), te.name);
}
te.r.addLast(e);
es.add(e);
points.add(te.points);
st.addPlayer(e.getOfflinePlayer(), Integer.MIN_VALUE);
}
}

scoreboard.initPoints(ao, es, points);
}

private int getReqSize(int teamIndex) {
return reqPlaceHolderPlayers.containsKey(teamIndex) ?
reqPlaceHolderPlayers.get(teamIndex).size() : 0;
}


private void addPlaceholder(ArenaTeam team, STeam t, boolean optionalTeam) {
private class TempEntry{
String name;

int points;
LinkedList<SEntry> r;
}

private TempEntry createEntry(ArenaTeam team, STeam t, boolean optionalTeam){
TempEntry te = new TempEntry();
String name;
int index;
int points;
if (!optionalTeam && getReqSize(team.getIndex()) < team.getMinPlayers()) {
r = reqPlaceHolderPlayers.get(team.getIndex());
if (r == null) {
r = new LinkedList<SEntry>();
reqPlaceHolderPlayers.put(team.getIndex(), r);
te.r = reqPlaceHolderPlayers.get(team.getIndex());
if (te.r == null) {
te.r = new LinkedList<SEntry>();
reqPlaceHolderPlayers.put(team.getIndex(), te.r);
}
name = "needed";
points = 1;
index = r.size();
te.points = 1;
index = te.r.size();
} else {
r = opPlaceHolderPlayers.get(team.getIndex());
if (r == null) {
r = new LinkedList<SEntry>();
opPlaceHolderPlayers.put(team.getIndex(), r);
te.r = opPlaceHolderPlayers.get(team.getIndex());
if (te.r == null) {
te.r = new LinkedList<SEntry>();
opPlaceHolderPlayers.put(team.getIndex(), te.r);
}
name = "open";
points = 0;
index = optionalTeam ? r.size() : team.getMinPlayers() + r.size();
te.points = 0;
index = optionalTeam ? te.r.size() : team.getMinPlayers() + te.r.size();
}

String dis = "- " + name + " -" + team.getTeamChatColor() + TeamUtil.getTeamChatColor(index);
SEntry e = scoreboard.getEntry(dis);
te.name = "- " + name + " -" + team.getTeamChatColor() + TeamUtil.getTeamChatColor(index);
return te;
}

private void addPlaceholder(ArenaTeam team, STeam t, boolean optionalTeam) {
TempEntry te = createEntry(team, t, optionalTeam);
SEntry e = scoreboard.getEntry(te.name);
if (e == null) {
e = scoreboard.createEntry(Bukkit.getOfflinePlayer(dis), dis);
ao.addEntry(e, points);
e = scoreboard.createEntry(OfflinePlayerTeams.getOfflinePlayer(te.name), te.name);
ao.addEntry(e, te.points);
} else {
ao.setPoints(e, points);
ao.setPoints(e, te.points);
}

r.addLast(e);
te.r.addLast(e);
t.addPlayer(e.getOfflinePlayer());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mc.alk.arena.controllers.joining.scoreboard;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import java.util.HashMap;

/**
* @author alkarin
*/
class OfflinePlayerTeams {
// static LoadingCache<String, OfflinePlayer> map = CacheBuilder.newBuilder()
// .expireAfterAccess(10, TimeUnit.MINUTES)
// .build(
// new CacheLoader<String, OfflinePlayer>() {
// @Override
// public OfflinePlayer load(String key) { // no checked exception
// return Bukkit.getOfflinePlayer(key);
// }
// });
//

static HashMap<String, OfflinePlayer> map = new HashMap<String, OfflinePlayer>();

static OfflinePlayer getOfflinePlayer(String name) {
OfflinePlayer op = map.get(name);
if (op == null) {
op = Bukkit.getOfflinePlayer(name);
map.put(name, op);
}
return op;
}

}
4 changes: 1 addition & 3 deletions src/java/mc/alk/arena/executors/BAExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import mc.alk.arena.controllers.ParamController;
import mc.alk.arena.controllers.PlayerController;
import mc.alk.arena.controllers.RoomController;
import mc.alk.arena.controllers.plugins.TrackerController;
import mc.alk.arena.controllers.TeamController;
import mc.alk.arena.controllers.WatchController;
import mc.alk.arena.controllers.containers.LobbyContainer;
Expand All @@ -29,6 +28,7 @@
import mc.alk.arena.controllers.plugins.EssentialsController;
import mc.alk.arena.controllers.plugins.HeroesController;
import mc.alk.arena.controllers.plugins.MobArenaInterface;
import mc.alk.arena.controllers.plugins.TrackerController;
import mc.alk.arena.events.arenas.ArenaCreateEvent;
import mc.alk.arena.events.arenas.ArenaDeleteEvent;
import mc.alk.arena.events.players.ArenaPlayerJoinEvent;
Expand Down Expand Up @@ -214,7 +214,6 @@ public boolean join(ArenaPlayer player, final MatchParams omp, JoinOptions jp, b
/// Can the player add this match/event at this moment?
if (!canJoin(player)) {
return true;}

/// Call the joining event
ArenaPlayerJoinEvent event = new ArenaPlayerJoinEvent(player);
event.callEvent();
Expand Down Expand Up @@ -345,7 +344,6 @@ public boolean join(ArenaPlayer player, final MatchParams omp, JoinOptions jp, b
default:
break;
}

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/java/mc/alk/arena/executors/BattleArenaDebugExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import mc.alk.arena.util.TeamUtil;
import mc.alk.arena.util.TimingUtil;
import mc.alk.arena.util.TimingUtil.TimingStat;
import mc.alk.profiling.Profiler;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
Expand Down Expand Up @@ -485,6 +486,8 @@ public boolean setTimings(CommandSender sender, boolean set) {

@MCCommand(cmds={"timings"}, admin=true)
public boolean showTimings(CommandSender sender, String[] args) {
Profiler.printTimings();

boolean useMs = !(args.length >1 && args[1].equalsIgnoreCase("ns"));
List<TimingUtil> timers = TimingUtil.getTimers();
if (timers == null){
Expand Down
2 changes: 1 addition & 1 deletion src/java/mc/alk/arena/executors/TeamExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean teamList(CommandSender sender) {
return sendMessage(sender,sb.toString());
}

@MCCommand(cmds={"add"}, usage="add", perm="arena.team.add")
@MCCommand(cmds={"join"}, usage="join", perm="arena.team.join")
public boolean teamJoin(ArenaPlayer player) {

ArenaTeam t = teamc.getSelfFormedTeam(player);
Expand Down
Loading

0 comments on commit 9dbca30

Please sign in to comment.