Skip to content

Commit

Permalink
Show teams when match is created, customisable message if you do not …
Browse files Browse the repository at this point in the history
…have permissions to request a private server, sync matches with API when connecting to Redis, add /bolt staff command, code and file size optimisations and bug fixes
  • Loading branch information
dentmaged committed Apr 10, 2021
1 parent 7af1216 commit 1552526
Show file tree
Hide file tree
Showing 29 changed files with 611 additions and 145 deletions.
11 changes: 3 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,23 @@
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>4.10.2</version>
<scope>provided</scope> <!-- Provided by DockerizedCraft -->
</dependency>
<dependency>
<groupId>de.craftmania</groupId>
<artifactId>DockerizedCraft</artifactId>
<version>0.2.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.exceptionflug</groupId>
<artifactId>protocolize-world</artifactId>
<version>1.6.7-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down Expand Up @@ -136,9 +134,6 @@
<include>*:*</include>
</includes>
<excludes>
<exclude>net.md-5:bungeecord-api</exclude>
<exclude>de.craftmania:DockerizedCraft</exclude>
<exclude>de.exceptionflug:protocolize-world</exclude>
</excludes>
</artifactSet>
</configuration>
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/rip/bolt/nerve/NervePlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rip.bolt.nerve;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sk89q.bungee.util.BungeeCommandsManager;
import com.sk89q.bungee.util.CommandExecutor;
import com.sk89q.bungee.util.CommandRegistration;
Expand All @@ -15,6 +16,7 @@
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import rip.bolt.nerve.api.APIManager;
import rip.bolt.nerve.api.DateModule;
import rip.bolt.nerve.commands.BoltCommands;
import rip.bolt.nerve.commands.PrivateCommand;
import rip.bolt.nerve.config.Config;
Expand All @@ -25,6 +27,7 @@
import rip.bolt.nerve.listener.ServerAddedListener;
import rip.bolt.nerve.managers.AutomoveManager;
import rip.bolt.nerve.managers.MatchRegistry;
import rip.bolt.nerve.managers.TeamInformationManager;
import rip.bolt.nerve.managers.VetoManager;
import rip.bolt.nerve.redis.RedisManager;

Expand All @@ -33,6 +36,7 @@ public class NervePlugin extends Plugin {
protected BungeeCommandsManager commands;
protected CommandRegistration cmdRegister;

protected ObjectMapper objectMapper;
protected APIManager apiManager;
protected RedisManager redisManager;

Expand All @@ -50,20 +54,22 @@ public void onEnable() {
appConfig = new ConfigManager(this, "config").get();
new ConfigManager(this, "template"); // copy template.yml from jar into plugins/Nerve/template.yml

apiManager = new APIManager();
objectMapper = new ObjectMapper().registerModule(new DateModule());
apiManager = new APIManager(objectMapper);
redisManager = new RedisManager();

matchRegistry = new MatchRegistry();
matchRegistry = new MatchRegistry(apiManager);
automoveManager = new AutomoveManager();
vetoManager = new VetoManager(apiManager);

matchRegistry.registerListener(automoveManager);
matchRegistry.registerListener(new TeamInformationManager());
matchRegistry.registerListener(vetoManager);

ProxyServer.getInstance().getPluginManager().registerListener(this, new ServerAddedListener());
ProxyServer.getInstance().getPluginManager().registerListener(this, new MatchUpdateListener(matchRegistry));
ProxyServer.getInstance().getPluginManager().registerListener(this, new MatchUpdateListener(matchRegistry, objectMapper));
ProxyServer.getInstance().getPluginManager().registerListener(this, new JoinListener(matchRegistry));
ProxyServer.getInstance().getPluginManager().registerListener(this, new QueueListener(matchRegistry));
ProxyServer.getInstance().getPluginManager().registerListener(this, new QueueListener(matchRegistry, objectMapper));

ProxyServer.getInstance().getPluginManager().registerCommand(this, new PrivateCommand());
setupCommands();
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/rip/bolt/nerve/api/APIManager.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rip.bolt.nerve.api;

import java.util.List;
import java.util.UUID;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -17,11 +18,11 @@ public class APIManager {

private final APIService apiService;

public APIManager() {
public APIManager(ObjectMapper objectMapper) {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(chain -> chain.proceed(chain.request().newBuilder().header("Authorization", "Bearer " + AppData.API.getKey()).build()));

Retrofit retrofit = new Retrofit.Builder().baseUrl(AppData.API.getURL()).addConverterFactory(JacksonConverterFactory.create(new ObjectMapper().registerModule(new DateModule()))).addCallAdapterFactory(new DefaultCallAdapterFactory<>()).client(httpClient.build()).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(AppData.API.getURL()).addConverterFactory(JacksonConverterFactory.create(objectMapper)).addCallAdapterFactory(new DefaultCallAdapterFactory<>()).client(httpClient.build()).build();
apiService = retrofit.create(APIService.class);
}

Expand All @@ -30,7 +31,11 @@ public PoolInformation getPoolInformation(int queueSize) {
}

public BoltResponse veto(Match match, UUID uuid, Veto veto) {
return apiService.veto(match.getMatchId(), uuid.toString(), veto);
return apiService.veto(match.getId(), uuid.toString(), veto);
}

public List<Match> matches() {
return apiService.matches();
}

}
6 changes: 6 additions & 0 deletions src/main/java/rip/bolt/nerve/api/APIService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package rip.bolt.nerve.api;

import java.util.List;

import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import rip.bolt.nerve.api.definitions.BoltResponse;
import rip.bolt.nerve.api.definitions.Match;
import rip.bolt.nerve.api.definitions.PoolInformation;
import rip.bolt.nerve.api.definitions.Veto;

Expand All @@ -16,4 +19,7 @@ public interface APIService {
@POST("ranked/matches/{match}/player/{uuid}/vote")
BoltResponse veto(@Path("match") String match, @Path("uuid") String uuid, @Body Veto veto);

@GET("ranked/matches")
List<Match> matches();

}
4 changes: 4 additions & 0 deletions src/main/java/rip/bolt/nerve/api/DateModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ public DateModule() {
}

private static class InstantSerializer extends JsonSerializer<Instant> {

@Override
public void serialize(Instant instant, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(instant.toString());
}

}

private static class InstantDeserializer extends JsonDeserializer<Instant> {

@Override
public Instant deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
return Instant.parse(jsonParser.getValueAsString());
}

}

}
66 changes: 57 additions & 9 deletions src/main/java/rip/bolt/nerve/api/definitions/Match.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
package rip.bolt.nerve.api.definitions;

import java.time.Instant;
import java.util.List;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access;

import rip.bolt.nerve.api.MatchStatus;
import net.md_5.bungee.api.connection.ProxiedPlayer;

@JsonIgnoreProperties(ignoreUnknown = true)
public class Match {

@JsonProperty("id")
private String matchId;

private String id;
private String map;
private String server;

@JsonProperty(access = Access.WRITE_ONLY)
private List<Team> teams;

private Team winner;

private Instant createdAt;
private Instant startedAt;
private Instant endedAt;

private MatchStatus status;

public String getMatchId() {
return matchId;
@JsonIgnore
private long lastUpdateTime;

public Match() {
this.lastUpdateTime = System.currentTimeMillis();
}

public void setMatchId(String matchId) {
this.matchId = matchId;
public String getId() {
return id;
}

public String getMap() {
Expand Down Expand Up @@ -64,6 +71,30 @@ public void setWinner(Team winner) {
this.winner = winner;
}

public Instant getCreatedAt() {
return createdAt;
}

public void setCreatedAt(Instant createdAt) {
this.createdAt = createdAt;
}

public Instant getStartedAt() {
return startedAt;
}

public void setStartedAt(Instant startedAt) {
this.startedAt = startedAt;
}

public Instant getEndedAt() {
return endedAt;
}

public void setEndedAt(Instant endedAt) {
this.endedAt = endedAt;
}

public MatchStatus getStatus() {
return status;
}
Expand All @@ -76,4 +107,21 @@ public int getQueueSize() {
return teams.get(0).getParticipations().size();
}

public Team getPlayerTeam(ProxiedPlayer player) {
return getPlayerTeam(player.getUniqueId());
}

public Team getPlayerTeam(UUID player) {
for (Team team : teams)
for (Participation participation : team.getParticipations())
if (participation.getUser().getUniqueId().equals(player))
return team;

return null;
}

public long getLastUpdateTime() {
return lastUpdateTime;
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rip.bolt.nerve.api;
package rip.bolt.nerve.api.definitions;

public enum MatchStatus {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Participation(User user) {
}

public Participation() {

}

public User getUser() {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/rip/bolt/nerve/api/definitions/QueueUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package rip.bolt.nerve.api.definitions;

import java.util.List;
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class QueueUpdate {

protected Action action;
protected User user;
protected int limit;
protected List<UUID> players;

public Action getAction() {
return action;
}

public User getUser() {
return user;
}

public int getLimit() {
return limit;
}

public List<UUID> getPlayers() {
return players;
}

public static enum Action {

JOIN,
LEAVE;

}

}
12 changes: 10 additions & 2 deletions src/main/java/rip/bolt/nerve/api/definitions/Team.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class Team {

private String name;
private String name, mmr;

private List<Participation> participations;

Expand All @@ -24,6 +24,14 @@ public String getName() {
return name;
}

public String getMMR() {
int idx = mmr.indexOf('.');
if (idx >= 0)
return mmr.substring(0, idx);

return mmr;
}

public List<Participation> getParticipations() {
return participations;
}
Expand All @@ -32,4 +40,4 @@ public List<User> getPlayers() {
return participations.stream().map(Participation::getUser).collect(Collectors.toList());
}

}
}
14 changes: 11 additions & 3 deletions src/main/java/rip/bolt/nerve/api/definitions/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
import java.util.UUID;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonIgnoreProperties(ignoreUnknown = true)
public class User {

private String uuid;
protected String username;

public UUID getUUID() {
return UUID.fromString(uuid);
@JsonProperty("uuid")
protected UUID uniqueId;

public String getUsername() {
return username;
}

public UUID getUniqueId() {
return uniqueId;
}

}
Loading

0 comments on commit 1552526

Please sign in to comment.