Skip to content

Commit

Permalink
Allow swapping default servers order
Browse files Browse the repository at this point in the history
See GTNewHorizons#2

Co-Authored-By: くぁーりぃ <[email protected]>
  • Loading branch information
glowredman and Quarri6343 committed Aug 31, 2022
1 parent acc64ca commit ad1bc2f
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public class ServerListMixin {
@Shadow
@Final
private List servers;

@Shadow
public void saveServerList() {
throw new IllegalStateException("Failed to apply mixin " + this.getClass().getName());
}

/**
* Removes all servers from servers.dat that are already in the default list
Expand Down Expand Up @@ -103,13 +108,23 @@ public int countServers() {
}

/**
* Cancel the swap if any of the ServerData objects to swap are in the default server list
* @author glowredman
* Takes two list indexes, and swaps their order around.
* @reason DefaultServerList
* @author Quarri6343
*/
@Inject(at = @At("HEAD"), cancellable = true, method = "swapServers(II)V")
private void swapServersCheck(int index1, int index2, CallbackInfo ci) {
if (index1 >= servers.size() || index2 >= servers.size()) {
ci.cancel();
@SuppressWarnings("unchecked")
@Overwrite
public void swapServers(int index1, int index2) {
if(index1 < servers.size() && index2 < servers.size()) {
ServerData serverData = this.getServerData(index1);
this.servers.set(index1, this.getServerData(index2));
this.servers.set(index2, serverData);
this.saveServerList();
} else if(index1 >= servers.size() && index2 >= servers.size()) {
ServerData serverData = this.getServerData(index1);
Config.SERVERS.set(index1 - servers.size(), this.getServerData(index2));
Config.SERVERS.set(index2 - servers.size(), serverData);
this.saveDefaultServerList(null);
}
}

Expand Down

0 comments on commit ad1bc2f

Please sign in to comment.