This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename EnumProtocol to ConnectionMode and move it out the API.
API endpoints have been added to replace old functionality
- Loading branch information
1 parent
0cdbc1f
commit 96e6f0a
Showing
13 changed files
with
174 additions
and
116 deletions.
There are no files selected for viewing
86 changes: 0 additions & 86 deletions
86
src/api/java/net/earthcomputer/multiconnect/api/EnumProtocol.java
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
src/api/java/net/earthcomputer/multiconnect/api/IProtocol.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package net.earthcomputer.multiconnect.api; | ||
|
||
/** | ||
* Contains information about a supported protocol version | ||
*/ | ||
public interface IProtocol { | ||
|
||
/** | ||
* Returns the protocol version ID, to be compared with values in {@link Protocols}. | ||
*/ | ||
int getValue(); | ||
|
||
/** | ||
* Returns the name of the Minecraft version that this protocol represents. | ||
*/ | ||
String getName(); | ||
|
||
} |
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
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
87 changes: 87 additions & 0 deletions
87
src/main/java/net/earthcomputer/multiconnect/impl/ConnectionMode.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package net.earthcomputer.multiconnect.impl; | ||
|
||
import net.earthcomputer.multiconnect.api.IProtocol; | ||
import net.earthcomputer.multiconnect.api.Protocols; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Enum constants for each protocol, and the auto connection mode | ||
*/ | ||
public enum ConnectionMode implements IProtocol { | ||
|
||
// Protocols should go in reverse chronological order | ||
AUTO("Auto", -1), | ||
V1_15_2("1.15.2", Protocols.V1_15_2), | ||
V1_15_1("1.15.1", Protocols.V1_15_1), | ||
V1_15("1.15", Protocols.V1_15), | ||
V1_14_4("1.14.4", Protocols.V1_14_4), | ||
V1_14_3("1.14.3", Protocols.V1_14_3), | ||
V1_14_2("1.14.2", Protocols.V1_14_2), | ||
V1_14_1("1.14.1", Protocols.V1_14_1), | ||
V1_14("1.14", Protocols.V1_14), | ||
V1_13_2("1.13.2", Protocols.V1_13_2), | ||
V1_13_1("1.13.1", Protocols.V1_13_1), | ||
V1_13("1.13", Protocols.V1_13), | ||
V1_12_2("1.12.2", Protocols.V1_12_2), | ||
V1_12_1("1.12.1", Protocols.V1_12_1), | ||
V1_12("1.12", Protocols.V1_12), | ||
; | ||
|
||
private final int value; | ||
private final String name; | ||
private final String assetId; | ||
|
||
ConnectionMode(final String name, final int value) { | ||
this(name, name, value); | ||
} | ||
|
||
ConnectionMode(final String name, final String assetId, final int value) { | ||
this.value = value; | ||
this.name = name; | ||
this.assetId = assetId; | ||
} | ||
|
||
@Override | ||
public int getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getAssetId() { | ||
return assetId; | ||
} | ||
|
||
private static final ConnectionMode[] VALUES = values(); | ||
private static final ConnectionMode[] PROTOCOLS = Arrays.stream(VALUES).filter(it -> it != AUTO).toArray(ConnectionMode[]::new); | ||
private static final Map<Integer, ConnectionMode> BY_VALUE = new HashMap<>(); | ||
|
||
public static ConnectionMode byValue(int value) { | ||
return BY_VALUE.getOrDefault(value, AUTO); | ||
} | ||
|
||
public static ConnectionMode[] protocolValues() { | ||
return PROTOCOLS; | ||
} | ||
|
||
public static boolean isSupportedProtocol(int protocol) { | ||
return byValue(protocol) != AUTO; | ||
} | ||
|
||
public ConnectionMode next() { | ||
return VALUES[(ordinal() + 1) % VALUES.length]; | ||
} | ||
|
||
static { | ||
for (ConnectionMode value : VALUES) { | ||
BY_VALUE.put(value.getValue(), value); | ||
} | ||
} | ||
|
||
} |
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
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
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
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
Oops, something went wrong.