generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
152 additions
and
22 deletions.
There are no files selected for viewing
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
4 changes: 3 additions & 1 deletion
4
src/client/java/net/vinrobot/mcemote/client/providers/IEmoteProvider.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package net.vinrobot.mcemote.client.providers; | ||
|
||
import net.vinrobot.mcemote.config.Configuration; | ||
|
||
public interface IEmoteProvider { | ||
void registerEmotes(IEmoteRegistry registry) throws Exception; | ||
void registerEmotes(Configuration config, IEmoteRegistry registry) throws Exception; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package net.vinrobot.mcemote.config; | ||
|
||
public interface Configuration { | ||
Option<String> twitchId(); | ||
} |
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,74 @@ | ||
package net.vinrobot.mcemote.config; | ||
|
||
import net.vinrobot.mcemote.config.impl.OptionImpl; | ||
|
||
import java.util.Optional; | ||
|
||
public interface Option<T> { | ||
static <T> Option<T> of(final T defaultValue) { | ||
return new OptionImpl<>(defaultValue); | ||
} | ||
|
||
static <T> Option<T> of(final T defaultValue, Optional<T> value) { | ||
final Option<T> option = of(defaultValue); | ||
option.set(value); | ||
return option; | ||
} | ||
|
||
static <T> Option<T> of(final T defaultValue, T value) { | ||
final Option<T> option = of(defaultValue); | ||
option.set(value); | ||
return option; | ||
} | ||
|
||
/** | ||
* Set the value of this option. | ||
* | ||
* @param value The optional value to set. | ||
* @return This option. | ||
*/ | ||
Option<T> set(Optional<T> value); | ||
|
||
/** | ||
* Set the value of this option. | ||
* | ||
* @param value The value to set. Must not be null. | ||
* @return This option. | ||
*/ | ||
default Option<T> set(T value) { | ||
return this.set(Optional.of(value)); | ||
} | ||
|
||
/** | ||
* Reset the value of this option. | ||
* | ||
* @return This option. | ||
*/ | ||
default Option<T> reset() { | ||
return this.set(Optional.empty()); | ||
} | ||
|
||
/** | ||
* Get the value of this option. | ||
* Returns the default value if the value is not set. | ||
* | ||
* @return The value of this option. | ||
*/ | ||
default T get() { | ||
return this.getRaw().orElseGet(this::getDefault); | ||
} | ||
|
||
/** | ||
* Get the raw value of this option. | ||
* | ||
* @return The raw value of this option. | ||
*/ | ||
Optional<T> getRaw(); | ||
|
||
/** | ||
* Get the default value of this option. | ||
* | ||
* @return The default value of this option. | ||
*/ | ||
T getDefault(); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/vinrobot/mcemote/config/impl/ConfigurationImpl.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,15 @@ | ||
package net.vinrobot.mcemote.config.impl; | ||
|
||
import net.vinrobot.mcemote.config.Configuration; | ||
import net.vinrobot.mcemote.config.Option; | ||
|
||
public final class ConfigurationImpl implements Configuration { | ||
private static final String SCRAPIE_TWITCH_ID = "40646018"; | ||
|
||
private final Option<String> twitchId = Option.of(SCRAPIE_TWITCH_ID); | ||
|
||
@Override | ||
public Option<String> twitchId() { | ||
return this.twitchId; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/net/vinrobot/mcemote/config/impl/OptionImpl.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,31 @@ | ||
package net.vinrobot.mcemote.config.impl; | ||
|
||
import net.vinrobot.mcemote.config.Option; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class OptionImpl<T> implements Option<T> { | ||
private final T defaultValue; | ||
private Optional<T> value = Optional.empty(); | ||
|
||
public OptionImpl(final T defaultValue) { | ||
this.defaultValue = defaultValue; | ||
} | ||
|
||
@Override | ||
public Option<T> set(final Optional<T> value) { | ||
this.value = Objects.requireNonNull(value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Optional<T> getRaw() { | ||
return this.value; | ||
} | ||
|
||
@Override | ||
public T getDefault() { | ||
return this.defaultValue; | ||
} | ||
} |