Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
Make PiShock API URL configurable just in case it needs to be changed…
Browse files Browse the repository at this point in the history
… in the future
  • Loading branch information
ojaha065 committed Jul 22, 2024
1 parent 8007c0e commit 00ba103
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 32 deletions.
33 changes: 25 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# eclipse
bin
*.launch
.settings
.metadata
.classpath
.project
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# idea
out
Expand All @@ -22,4 +39,4 @@ eclipse
run

# Files from Forge MDK
forge*changelog.txt
forge*changelog.txt
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ the intensity of which can be configured and will scale up based on the amount o
1. Have a working Minecraft and Forge installation. See [How to install Forge](https://www.wikihow.com/Install-Minecraft-Forge) if you're unsure.
* Make sure you've launched the game at least once with Forge installed so the required folder structure is generated.
2. Download the latest release jar from [here](https://github.com/ojaha065/PiShockForMC/releases).
3. Drop the downloaded .jar file into `mods` folder inside Minecraft game directory. See [Mojang documentation](https://help.minecraft.net/hc/en-us/articles/4409159214605) if you're unsure how to find the correct game directory.
3. Drop the downloaded .jar file into `mods` folder inside Minecraft game directory. See the [Mojang documentation](https://help.minecraft.net/hc/en-us/articles/4409159214605) if you're unsure how to find the correct game directory.
4. Run the game once so a configuration file for the mod gets generated.
5. See the _Mod configuration_ section below. The configuration file can be found inside `config` folder inside Minecraft game directory.
6. Launch the game again. If everything is set correctly, the shocker will vibrate once for one second during the Minecraft startup process.
Expand Down Expand Up @@ -138,7 +138,7 @@ Please open [an issue](https://github.com/ojaha065/PiShockForMC/issues) here on

## TODO (PRs welcome)
* **Support for multiple shockers**
* I currently only own one, so testing and debugging would be kinda hard.
* I currently only own one, so testing and debugging would be kinda hard for me.
* In-game configuration GUI
* **More configuration options**
* Configurable shock duration
Expand All @@ -150,9 +150,7 @@ Although nothing about this repository is inherently age-gated,
the PiShock device and themes around it are targeted towards mature audiences only.
Proceed at your own discretion.

The authors of this mod are not responsible for any injuries caused by use of any shock collar.
It's not recommended to put any kind of electrical device near the heart
or use any kind of shock collar if you have a heart condition.
Shock collars are not meant for use on humans and can cause serious injury, even cardiac events.
We kindly urge you to prioritize safety,
understand your personal and others' limitations, and exercise caution at all times.
PiShock or the authors of this mod are not responsible for any harm
caused by misuse of the shock collar sold along with the PiShock device.
We do not recommend putting any kind of electrical device near the heart or use if you have a heart condition.
Shock collars are not meant for use on humans and can cause serious injury, including cardiac events.
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
plugins {
id 'eclipse'
id 'idea'
id 'net.minecraftforge.gradle' version '[6.0.24,6.2)'
}

version = '1.21-2.0.0.0'
version = '1.21-2.0.1.0'
group = 'fi.kissakala'
base.archivesName = 'pishockmc'

Expand All @@ -20,7 +19,6 @@ minecraft {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
property 'forge.enabledGameTestNamespaces', 'pishockmc'
}
}
}
Expand All @@ -33,13 +31,13 @@ repositories {
}

dependencies {
minecraft "net.minecraftforge:forge:1.21-51.0.8"
minecraft "net.minecraftforge:forge:1.21-51.0.26"

// Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transitive dependencies request 6.0+
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
}

jar {
tasks.named('jar', Jar).configure {
manifest {
attributes([
"Specification-Title" : "PiShock for Minecraft",
Expand Down
9 changes: 6 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -200,7 +203,7 @@ fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/fi/kissakala/pishockmc/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
public class Config {
public static ForgeConfigSpec INSTANCE;

public static ForgeConfigSpec.ConfigValue<String> pishockAPIURL;

public static ForgeConfigSpec.ConfigValue<String> username;
public static ForgeConfigSpec.ConfigValue<String> apikey;
public static ForgeConfigSpec.ConfigValue<String> code;
Expand All @@ -21,6 +23,10 @@ public class Config {
}

private static ForgeConfigSpec.Builder build(final ForgeConfigSpec.Builder builder) {
pishockAPIURL = builder
.comment("Set if you want to use a different URL for accessing the PiShock API for some reason. Usually you don't need to change this.")
.define("pishock.APIURL", "https://do.pishock.com/api/");

username = builder
.comment("Username you use to log into PiShock.com. Can be found in the Account section of the website.")
.define("pishock.username", "");
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fi/kissakala/pishockmc/PiShockAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class PiShockAPI implements Closeable {

public PiShockAPI() {
try {
this.API_URL = new URI("https://do.pishock.com/api/");
this.API_URL = new URI(StringUtils.appendIfMissing(Config.pishockAPIURL.get(), "/"));
this.worker = Executors.newSingleThreadExecutor();

connect().get();
Expand Down Expand Up @@ -65,7 +65,7 @@ public void sendRequest(final OP_CODE operation, final int intensity, final int
Map.entry("Intensity", Utils.clamp(intensity, 1, 100))
);

final HttpURLConnection con = (HttpURLConnection) API_URL.resolve("./apioperate").toURL().openConnection();
final HttpURLConnection con = (HttpURLConnection) API_URL.resolve("apioperate").toURL().openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "text/plain");
Expand All @@ -85,7 +85,7 @@ public void sendRequest(final OP_CODE operation, final int intensity, final int
throw new RuntimeException("PiShock API request failed: " + responseString);
}
} catch (final Exception error) {
LOGGER.error("Error accessing PiShock API", error);
LOGGER.error(Utils.log("Error accessing PiShock API {API URL: %s}".formatted(this.API_URL.toString())), error);
}
});
}
Expand All @@ -100,7 +100,7 @@ public CompletableFuture<CONNECTION_STATE> connect() {

return getShockerInfo().orTimeout(8, TimeUnit.SECONDS).handle((shockerInfo, error) -> {
if (error != null) {
LOGGER.warn(Utils.log("Could not get Shocker Info from PiShock API"), error);
LOGGER.warn(Utils.log("Error accessing PiShock API {API URL: %s}".formatted(this.API_URL.toString())), error);

this.connectionState = CONNECTION_STATE.NOT_CONNECTED;
return this.connectionState;
Expand Down Expand Up @@ -169,7 +169,7 @@ private CompletableFuture<GetShockerInfoResponse> getShockerInfo() {
Map.entry("Code", Config.code.get())
);

final HttpURLConnection con = (HttpURLConnection) API_URL.resolve("./GetShockerInfo").toURL().openConnection();
final HttpURLConnection con = (HttpURLConnection) API_URL.resolve("GetShockerInfo").toURL().openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ issueTrackerURL="https://github.com/ojaha065/PiShockForMC/issues"

[[mods]]
modId="pishockmc"
version="1.21-2.0.0.0"
version="1.21-2.0.1.0"
displayName="PiShock for Minecraft"

#updateJSONURL="https://change.me.example.invalid/updates.json" # TODO
Expand All @@ -23,7 +23,7 @@ For detailed setup instructions and configuration, please refer to the GitHub pa
---
Authors of this mod are not responsible for any injuries caused by use of the shock collar. It's not recommended to put any kind of electrical device near the heart or use any kind of shock collar if you have a heart condition. Shock collars are not meant for use on humans and can cause serious injury, even cardiac events. We kindly urge you to prioritize safety, understand your personal and other's limitations, and exercise caution at all times.
The authors of this mod are not responsible for any harm caused by misuse of the shock collar sold along with the PiShock device. We do not recommend putting any kind of electrical device near the heart or use if you have a heart condition. Shock collars are not meant for use on humans and can cause serious injury including cardiac events.
'''

# Display Test controls the display of the mod in the server connection screen
Expand All @@ -38,6 +38,6 @@ displayTest="IGNORE_ALL_VERSION" # This is a client-only mod
[[dependencies.pishockmc]]
modId="minecraft"
mandatory=true
versionRange="[1.19,1.22)"
versionRange="[1.21,1.22)"
ordering="AFTER"
side="BOTH"

0 comments on commit 00ba103

Please sign in to comment.