diff --git a/.gitignore b/.gitignore index ecafe1d..da24c04 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ LICENSE*.txt Paulscode*.txt run/ +.idea/ eclipse/ .gradel/ CREDITS-fml.txt diff --git a/build.gradle b/build.gradle index 6f979f9..7ce2f26 100644 --- a/build.gradle +++ b/build.gradle @@ -1,87 +1,147 @@ - -// For those who want the bleeding edge -buildscript { - repositories { - jcenter() - maven { - name = "forge" - url = "http://files.minecraftforge.net/maven" - } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' - } -} -apply plugin: 'net.minecraftforge.gradle.forge' - -/* -// for people who want stable - not yet functional for MC 1.8.8 - we require the forgegradle 2.1 snapshot -plugins { - id "net.minecraftforge.gradle.forge" version "2.0.2" -} -*/ -version = "1.10" -group= "colecf.safechat" // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = "Safechat" - -sourceCompatibility = targetCompatibility = "1.6" // Need this here so eclipse task generates correctly. -compileJava { - sourceCompatibility = targetCompatibility = "1.6" -} - -minecraft { - version = "1.10.2-12.18.1.2073" - runDir = "run" - - // the mappings can be changed at any time, and must be in the following format. - // snapshot_YYYYMMDD snapshot are built nightly. - // stable_# stables are built at the discretion of the MCP team. - // Use non-default mappings at your own risk. they may not allways work. - // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "snapshot_20160518" - // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. -} - -dependencies { - // you may put jars on which you depend on in ./libs - // or you may define them like so.. - //compile "some.group:artifact:version:classifier" - //compile "some.group:artifact:version" - - // real examples - //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env - //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env - - // the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. - //provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided, - // except that these dependencies get remapped to your current MCP mappings - //deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev' - //deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev' - - // for more info... - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html - -} - -processResources -{ - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - // copy everything else, thats not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} +buildscript { + repositories { + maven { url = 'https://files.minecraftforge.net/maven' } + jcenter() + mavenCentral() + } + dependencies { + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + } +} +apply plugin: 'net.minecraftforge.gradle' +// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. +apply plugin: 'eclipse' +apply plugin: 'maven-publish' + +version = '1.16.1' +group = 'colecf.safechat' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = 'Safechat' + +sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. + +println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) +minecraft { + // The mappings can be changed at any time, and must be in the following format. + // snapshot_YYYYMMDD Snapshot are built nightly. + // stable_# Stables are built at the discretion of the MCP team. + // Use non-default mappings at your own risk. they may not always work. + // Simply re-run your setup task after changing the mappings to update your workspace. + mappings channel: 'snapshot', version: '20200514-1.16' + // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. + + // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + + // Default run configurations. + // These can be tweaked, removed, or duplicated as needed. + runs { + client { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + mods { + safechat { + source sourceSets.main + } + } + } + + server { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + mods { + safechat { + source sourceSets.main + } + } + } + + data { + workingDirectory project.file('run') + + // Recommended logging data for a userdev environment + property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP' + + // Recommended logging level for the console + property 'forge.logging.console.level', 'debug' + + args '--mod', 'safechat', '--all', '--output', file('src/generated/resources/') + + mods { + safechat { + source sourceSets.main + } + } + } + } +} + +dependencies { + // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed + // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. + // The userdev artifact is a special name and will get all sorts of transformations applied to it. + minecraft 'net.minecraftforge:forge:1.16.1-32.0.70' + + // You may put jars on which you depend on in ./libs or you may define them like so.. + // compile "some.group:artifact:version:classifier" + // compile "some.group:artifact:version" + + // Real examples + // compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env + // compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env + + // The 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime. + // provided 'com.mod-buildcraft:buildcraft:6.0.8:dev' + + // These dependencies get remapped to your current MCP mappings + // deobf 'com.mod-buildcraft:buildcraft:6.0.8:dev' + + // For more info... + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html + +} + +// Example for how to get properties into the manifest for reading by the runtime.. +jar { + manifest { + attributes([ + "Specification-Title": "Safechat", + "Specification-Vendor": "Safechatcolecf", + "Specification-Version": "1.16.1", // We are version 1.16.1 of ourselves + "Implementation-Title": project.name, + "Implementation-Version": "${version}", + "Implementation-Vendor" :"Safechatcolecf", + "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") + ]) + } +} + +// Example configuration to allow publishing using the maven-publish task +// This is the preferred method to reobfuscate your jar file +jar.finalizedBy('reobfJar') +// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing +//publish.dependsOn('reobfJar') + +publishing { + publications { + mavenJava(MavenPublication) { + artifact jar + } + } + repositories { + maven { + url "file:///${project.projectDir}/mcmodsrepo" + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 30d399d..7a3265e 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba7..2a4b36c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Sep 14 12:28:28 PDT 2015 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +#Sun Jul 19 15:37:58 PDT 2020 +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 91a7e26..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec9973..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/src/main/java/colecf/safechat/ChatEvents.java b/src/main/java/colecf/safechat/ChatEvents.java index 6b3cd47..5bb5baf 100644 --- a/src/main/java/colecf/safechat/ChatEvents.java +++ b/src/main/java/colecf/safechat/ChatEvents.java @@ -1,180 +1,103 @@ package colecf.safechat; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +import java.util.Arrays; +import java.util.Optional; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.minecraft.client.Minecraft; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextComponentString; -import net.minecraftforge.client.event.ClientChatReceivedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +public class ChatEvents { + private final String replaceText; + private final Pattern[] badWords; + private final String deleteMessage; + private final boolean deleteWholeWord; + private final String[][] customReplaces; + + private boolean firstChatMessage = true; + + public ChatEvents(Properties swearingConfigFile) { + replaceText = swearingConfigFile.getProperty("replaceText", "***"); + badWords = Arrays.stream(swearingConfigFile.getProperty("words", "").split(",")) + .filter(w -> w.length() > 0) + .map(w -> Pattern.compile("(?i)" + w)) + .toArray(Pattern[]::new); + deleteMessage = swearingConfigFile.getProperty("deleteMessage", "false"); + deleteWholeWord = "true".contentEquals(swearingConfigFile.getProperty("deleteWholeWord", "false")); + if (swearingConfigFile.getProperty("customReplace") != null) { + customReplaces = Arrays.stream(swearingConfigFile.getProperty("customReplace").split(",")) + .map(s -> s.split(":")) + .toArray(String[][]::new); + } else { + customReplaces = new String[][]{}; + } + } -public class ChatEvents -{ - static String replaceText; - static String[] badWords; - static String deleteMessage; - static String deleteWholeWordString; - static String[][] customReplaces; - - public static void init() - { - Properties swearingConfigFile = Safechat.swearingConfigFile; - replaceText = swearingConfigFile.getProperty("replaceText"); - badWords = swearingConfigFile.getProperty("words").split(","); - deleteMessage = swearingConfigFile.getProperty("deleteMessage"); - deleteWholeWordString = swearingConfigFile.getProperty("deleteWholeWord"); - if(swearingConfigFile.getProperty("customReplace")==null) - { - System.out.println("Generating customReplace in old config file"); - appendToConfig("\n# Phrases to replace with other phrases:\n" - + "customReplace=a safechat test:replaced,another safechat test:replaced2\n\n"); - } - String[] temp = swearingConfigFile.getProperty("customReplace").split(","); - ArrayList temp2 = new ArrayList(); - for(int i=0; i') != -1)) - { - for (int i = 0; i < badWords.length; i++) - { - Pattern p = Pattern.compile("(?i)" + badWords[i]); - Matcher m = p.matcher(s + " "); - System.out.println(badWords[i]); - if (m.find()) - { - s = s.substring(0, s.indexOf('>') + 1) + " (Message has been deleted by SafeChat)"; - break; - } - } - } - else - for (int i = 0; i < badWords.length; i++) - { - Pattern p = Pattern.compile("(?i)" + badWords[i]); - Matcher m = p.matcher(s + " "); - if (m.find()) - { - s = "(Message has been deleted by SafeChat)"; - break; - } - } - } - else if (deleteMessage.toLowerCase().equals("hide")) - { - for (int i = 0; i < badWords.length; i++) - { - Pattern p = Pattern.compile("(?i)" + badWords[i]); - Matcher m = p.matcher(s + " "); - if (m.find()) - { - abort = true; - } - } - } - else if (deleteMessage.toLowerCase().equals("nochat")) - { - abort = true; - } + String s = event.getMessage().getString(); + + boolean abort = false; - for (int i = 0; i < badWords.length; i++) - { - String regex = "(?i)" + badWords[i]; - if(!deleteWholeWord) - { - s = (s+" ").replaceAll(regex, replaceText); - if(s.charAt(s.length()-1)==' ') - { - s = s.substring(0, s.length()-1); + switch (deleteMessage.toLowerCase()) { + case "delete": + for (Pattern badWord : badWords) { + if (badWord.matcher(s).find()) { + Matcher m = Pattern.compile("(^<[^>]+> )?.*").matcher(s); + m.find(); + s = Optional.ofNullable(m.group(1)).orElse("") + "(Message has been deleted by SafeChat)"; + break; + } } - } else - { - Matcher m = Pattern.compile(regex).matcher(s+" "); - while(m.find()) - { - int start = findSpaceBefore(s, m.start()); - int end = findSpaceAfter(s+" ", m.end()); - s = s.substring(0, start+1) + replaceText + s.substring(end); - } - } + break; + case "hide": + for (Pattern badWord : badWords) { + Matcher m = badWord.matcher(s); + if (m.find()) { + abort = true; + break; + } + } + break; + case "nochat": + abort = true; + break; + default: + for (Pattern badWord : badWords) { + if (!deleteWholeWord) { + s = badWord.matcher(s).replaceAll(replaceText); + } else { + Matcher m = badWord.matcher(s); + while (m.find()) { + int start = s.lastIndexOf(' ', m.start()); + int end = s.indexOf(' ', m.end()); + s = s.substring(0, start + 1) + replaceText + s.substring(end); + } + } + } + break; } - - for(int i=0; i= 0 && s.charAt(index)!=' ') - { - index--; - } - return index; - } - private int findSpaceAfter(String s, int index) - { - while(index < s.length() && s.charAt(index)!=' ') - { - index++; - } - return index; - } - - public static void appendToConfig(String toAppend) - { - String path = Minecraft.getMinecraft().mcDataDir.toString() + "/config/safechat.properties"; + for (String[] customReplace : customReplaces) { + s = s.replaceAll("(?i)" + customReplace[0], customReplace[1]); + } - FileOutputStream fop = null; - try - { - FileWriter fw = new FileWriter(path,true); - fw.write(toAppend); - fw.close(); - } - catch (FileNotFoundException e) { - System.out.println("ERROR: Couldn't open config file when it's supposed to be generated!"); - } catch (IOException e) { - e.printStackTrace(); - } + event.setCanceled(true); + if (!abort) { + Minecraft.getInstance().ingameGUI.getChatGUI().printChatMessage(new StringTextComponent(s)); + } } } diff --git a/src/main/java/colecf/safechat/Safechat.java b/src/main/java/colecf/safechat/Safechat.java index 2882d7d..c62a0a8 100644 --- a/src/main/java/colecf/safechat/Safechat.java +++ b/src/main/java/colecf/safechat/Safechat.java @@ -1,79 +1,74 @@ package colecf.safechat; -import java.io.File; +import net.minecraft.client.Minecraft; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; -import net.minecraft.client.Minecraft; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; - -@Mod(modid="colecf.Safechat", name="Safechat", version="1.10.2") -public class Safechat -{ - - @Mod.Instance("Generic") - public static Safechat instance; - public static Properties swearingConfigFile = new Properties(); - - @EventHandler - public void load(FMLInitializationEvent event) { - String path = Minecraft.getMinecraft().mcDataDir.toString() + "/config/safechat.properties"; - - FileOutputStream fop = null; - try - { - swearingConfigFile.load(new FileInputStream(path)); - } - catch (FileNotFoundException e) { - try { - String content = "# Default settings for safechat for minecraft 1.5.2\n\n" - + "# What will appear instead of swear words, if deleteMessage is false\nreplaceText=***\n\n" - + "# For deleteMessage, you can put the following:\n# hide: doesn't show the message, as if it never existed\n# delete: deletes the message but lets you see the username\n# nochat: disables chat entirely. This will also prevent you from seeing commands\n# like /home, but you'll still be able to use them. You won't be able to see yourself\n# talk, but others will\n# false: Simply **** out the words\n" - + "deleteMessage=false\n\n" - + "# If deleteWholeWord is true, and it finds a swear word that's part of another word,\n# (For example, swearwordalicious) it will replace the rest of the word as well.\n" - + "deleteWholeWord=false\n\n" - + "# Phrases to replace with other phrases:\n" - + "customReplace=a safechat test:replaced,another safechat test:replaced2\n\n" - + "# The swear words (or phrases).\n# They are separated by commas, so obviously they can't contain commas themselves.\n# They support java regular expressions: http://docs.oracle.com/javase/tutorial/essential/regex/\n" - + "words=fucking,fucked,8\\=*D~*,ahole,anus,ash0le,ash0les,asholes, ass ,Ass Monkey,Assface,assh0le,assh0lez,asshole,assholes,assholz,asswipe,azzhole,bassterds,bastard,bastards,bastardz,basterds,basterdz,Biatch,bitch,bitches,Blow Job,boffing,butthole,buttwipe,c0ck,c0cks,c0k,Carpet Muncher,cawk,cawks,Clit,cnts,cntz,cock,cockhead,cock-head,cocks,CockSucker,cock-sucker,crap, cum ,cunt,cunts,cuntz,dick,dild0,dild0s,dildo,dildos,dilld0,dilld0s,dominatricks,dominatrics,dominatrix,dyke,enema,f u c k,f u c k e r,fag,fag1t,faget,fagg1t,faggit,faggot,fagit,fags,fagz,faig,faigs,flipping the bird,fuck,fucker,fuckin,fucking,fucks,Fudge Packer,fuk,Fukah,Fuken,fuker,Fukin,Fukk,Fukkah,Fukken,Fukker,Fukkin,g00k,gay,gayboy,gaygirl,gays,gayz,God-damned,h00r,h0ar,h0re,hells,hoar,hoor,hoore,jackoff,jap,japs,jerk-off,jisim,jiss,jizm,jizz,knob,knobs,knobz,kunt,kunts,kuntz,Lesbian,Lezzian,Lipshits,Lipshitz,masochist,masokist,massterbait,masstrbait,masstrbate,masterbaiter,masterbate,masterbates,Motha Fucker,Motha Fuker,Motha Fukkah,Motha Fukker,Mother Fucker,Mother Fukah,Mother Fuker,Mother Fukkah,Mother Fukker,mother-fucker,Mutha Fucker,Mutha Fukah,Mutha Fuker,Mutha Fukkah,Mutha Fukker,n1gr,nastt,nigger;,nigur;,niiger;,niigr;,orafis,orgasim;,orgasm,orgasum,oriface,orifice,orifiss,packi,packie,packy,paki,pakie,paky,pecker,peeenus,peeenusss,peenus,peinus,pen1s,penas,penis,penis-breath,penus,penuus,Phuc,Phuck,Phuk,Phuker,Phukker,polac,polack,polak,Poonani,pr1c,pr1ck,pr1k,pusse,pussee,pussy,puuke,puuker,queers,queerz,qweers,qweerz,qweir,recktum,rectum,retard,sadist,scank,schlong,screwing,semen,sex,sexy,Sh\\!t,sh1t,sh1ter,sh1ts,sh1tter,sh1tz,shit,shits,shitter,Shitty,Shity,shitz,Shyt,Shyte,Shytty,Shyty,skanck,skank,skankee,skankey,skanks,Skanky,slut,sluts,Slutty,slutz,son-of-a-bitch, tit ,turd,va1jina,vag1na,vagiina,vagina,vaj1na,vajina,vullva,vulva,w0p,wh00r,wh0re,whore,xrated,xxx,b\\!+ch,bitch,blowjob,clit,arschloch,fuck,shit,asshole,b\\!tch,b17ch,b1tch,bastard,bi+ch,boiolas,buceta,c0ck,cawk,chink,cipa,clits,cock,cum,cunt,dildo,dirsa,ejakulate,fatass,fcuk,fuk,fux0r,hoer,hore,jism,kawk,l3itch,l3i+ch,lesbian,masturbate,masterbat,masterbat3,motherfucker,mofo,nazi,nigga,nigger,nutsack,phuck,pimpis,pusse,pussy,scrotum,sh\\!t,shemale,slut,smut,teets,tits,boobs,b00bs,teez,testical,testicle,titt,w00se,jackoff,wank,whoar,whore,damn,dyke,fuck,shit,@$$,amcik,andskota,arse,assrammer,ayir,bi7ch,bitch,bollock,butt-pirate,cabron,cazzo,chraa,chuj,Cock,cunt,d4mn,daygo,dego,dick,dike,dupa,dziwka,ejackulate,Ekrem,Ekto,enculer,faen,fag,fanculo,fanny,feces,feg,Felcher,ficken,fitt,Flikker,foreskin,Fotze,fuk,futkretzn,gay,gook,guiena,h0r,helvete,hoer,honkey,Huevon,hui,injun,jizz,kanker,kike,klootzak,kraut,knulle,kuk,kuksuger,Kurac,kurwa,kusi,kyrpa,lesbo,mamhoon,masturbat,merd,mibun,monkleigh,mouliewop,muie,mulkku,muschi,nazis,nepesaurio,nigger,orospu,paska,perse,picka,pierdol,pillu,pimmel,piss,pizda,poontsee,poop,porn,p0rn,pr0n,preteen,pula,pule,puta,puto,qahbeh,queef,rautenberg,schaffer,scheiss,schlampe,schmuck,screw,sh\\!t,sharmuta,sharmute,shipal,shiz,skribz,skurwysyn,sphencter,spic,spierdalaj,splooge,suka,b00b,testicle,titt,twat,vittu,wank,wetback,wichser,wop, yed ,zabourah\n\n"; +@Mod("colecf_safechat") +public class Safechat { + public Safechat() { + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + MinecraftForge.EVENT_BUS.register(this); + } - File file = new File(path); - fop = new FileOutputStream(file); + // For some reason this doesn't seem to work with @SubscribeEvent, and instead + // had to be registered with FMLJavaModLoadingContext + public void setup(FMLCommonSetupEvent event) { + MinecraftForge.EVENT_BUS.register(new ChatEvents(loadProperties())); + } - if (!file.exists()) { - file.createNewFile(); - } + public static Properties loadProperties() { + Properties swearingConfigFile = new Properties(); + String path = Minecraft.getInstance().gameDir.toString() + "/config/safechat.properties"; - byte[] contentInBytes = content.getBytes(); + try { + try (FileInputStream fip = new FileInputStream(path)) { + swearingConfigFile.load(fip); + } + } catch (FileNotFoundException e) { + try { + String content = "# Default settings for safechat for minecraft 1.16.1\n\n" + + "# What will appear instead of swear words, if deleteMessage is false\n" + + "replaceText=***\n\n" + + "# For deleteMessage, you can put the following:\n" + + "# hide: doesn't show the message, as if it never existed\n" + + "# delete: deletes the message but lets you see the username\n" + + "# nochat: disables chat entirely. This will also prevent you from seeing commands\n" + + "# like /home, but you'll still be able to use them. You won't be able to see yourself\n" + + "# talk, but others will\n# false: Simply **** out the words\n" + + "deleteMessage=false\n\n" + + "# If deleteWholeWord is true, and it finds a swear word that's part of another word,\n" + + "# (For example, swearwordalicious) it will replace the rest of the word as well.\n" + + "deleteWholeWord=false\n\n" + + "# Phrases to replace with other phrases:\n" + + "customReplace=a_safechat_test:replaced,another_safechat_test:replaced2\n\n" + + "# The swear words (or phrases).\n# They are separated by commas, so they can't contain commas themselves.\n" + + "# They support java regular expressions: http://docs.oracle.com/javase/tutorial/essential/regex/\n" + + "# Backslashes are used to escape newlines in this config file, so you may have to double backslash some things.\n" + + "words=fucking,fucked,8=+D~*,ahole,anus,ash0le,ash0les,asholes,\\\\bass\\\\b,Ass Monkey,Assface,assh0le,assh0lez,asshole,assholes,assholz,asswipe,azzhole,bassterds,bastard,bastards,bastardz,basterds,basterdz,Biatch,bitch,bitches,Blow Job,boffing,butthole,buttwipe,c0ck,c0cks,c0k,Carpet Muncher,cawk,cawks,Clit,cnts,cntz,cock,cockhead,cock-head,cocks,CockSucker,cock-sucker,crap, cum ,cunt,cunts,cuntz,dick,dild0,dild0s,dildo,dildos,dilld0,dilld0s,dominatricks,dominatrics,dominatrix,dyke,enema,f u c k,f u c k e r,fag,fag1t,faget,fagg1t,faggit,faggot,fagit,fags,fagz,faig,faigs,flipping the bird,fuck,fucker,fuckin,fucking,fucks,Fudge Packer,fuk,Fukah,Fuken,fuker,Fukin,Fukk,Fukkah,Fukken,Fukker,Fukkin,g00k,gay,gayboy,gaygirl,gays,gayz,God-damned,h00r,h0ar,h0re,hells,hoar,hoor,hoore,jackoff,jap,japs,jerk-off,jisim,jiss,jizm,jizz,knob,knobs,knobz,kunt,kunts,kuntz,Lesbian,Lezzian,Lipshits,Lipshitz,masochist,masokist,massterbait,masstrbait,masstrbate,masterbaiter,masterbate,masterbates,Motha Fucker,Motha Fuker,Motha Fukkah,Motha Fukker,Mother Fucker,Mother Fukah,Mother Fuker,Mother Fukkah,Mother Fukker,mother-fucker,Mutha Fucker,Mutha Fukah,Mutha Fuker,Mutha Fukkah,Mutha Fukker,n1gr,nastt,nigger;,nigur;,niiger;,niigr;,orafis,orgasim;,orgasm,orgasum,oriface,orifice,orifiss,packi,packie,packy,paki,pakie,paky,pecker,peeenus,peeenusss,peenus,peinus,pen1s,penas,penis,penis-breath,penus,penuus,Phuc,Phuck,Phuk,Phuker,Phukker,polac,polack,polak,Poonani,pr1c,pr1ck,pr1k,pusse,pussee,pussy,puuke,puuker,queers,queerz,qweers,qweerz,qweir,recktum,rectum,retard,sadist,scank,schlong,screwing,semen,sex,sexy,Sh\\!t,sh1t,sh1ter,sh1ts,sh1tter,sh1tz,shit,shits,shitter,Shitty,Shity,shitz,Shyt,Shyte,Shytty,Shyty,skanck,skank,skankee,skankey,skanks,Skanky,slut,sluts,Slutty,slutz,son-of-a-bitch, tit ,turd,va1jina,vag1na,vagiina,vagina,vaj1na,vajina,vullva,vulva,w0p,wh00r,wh0re,whore,xrated,xxx,b\\!+ch,bitch,blowjob,clit,arschloch,fuck,shit,asshole,b\\!tch,b17ch,b1tch,bastard,bi+ch,boiolas,buceta,c0ck,cawk,chink,cipa,clits,cock,cum,cunt,dildo,dirsa,ejakulate,fatass,fcuk,fuk,fux0r,hoer,hore,jism,kawk,l3itch,l3i+ch,lesbian,masturbate,masterbat,masterbat3,motherfucker,mofo,nazi,nigga,nigger,nutsack,phuck,pimpis,pusse,pussy,scrotum,sh!t,shemale,slut,smut,teets,tits,boobs,b00bs,teez,testical,testicle,titt,w00se,jackoff,wank,whoar,whore,damn,dyke,fuck,shit,@$$,amcik,andskota,arse,assrammer,ayir,bi7ch,bitch,bollock,butt-pirate,cabron,cazzo,chraa,chuj,Cock,cunt,d4mn,daygo,dego,dick,dike,dupa,dziwka,ejackulate,Ekrem,Ekto,enculer,faen,fag,fanculo,fanny,feces,feg,Felcher,ficken,fitt,Flikker,foreskin,Fotze,fuk,futkretzn,gay,gook,guiena,h0r,helvete,hoer,honkey,Huevon,hui,injun,jizz,kanker,kike,klootzak,kraut,knulle,kuk,kuksuger,Kurac,kurwa,kusi,kyrpa,lesbo,mamhoon,masturbat,merd,mibun,monkleigh,mouliewop,muie,mulkku,muschi,nazis,nepesaurio,nigger,orospu,paska,perse,picka,pierdol,pillu,pimmel,piss,pizda,poontsee,poop,porn,p0rn,pr0n,preteen,pula,pule,puta,puto,qahbeh,queef,rautenberg,schaffer,scheiss,schlampe,schmuck,screw,sh!t,sharmuta,sharmute,shipal,shiz,skribz,skurwysyn,sphencter,spic,spierdalaj,splooge,suka,b00b,testicle,titt,twat,vittu,wank,wetback,wichser,wop,\\\\byed\\\\b,zabourah\n\n"; - fop.write(contentInBytes); - fop.flush(); - fop.close(); + try (FileOutputStream fop = new FileOutputStream(path)) { + fop.write(content.getBytes()); + } - swearingConfigFile.load(new FileInputStream(path)); - } - catch (IOException e1) { - e1.printStackTrace(); - } finally { - try { - if (fop != null) - fop.close(); - } - catch (IOException e2) { - e2.printStackTrace(); - } - } - } catch (IOException e) { - e.printStackTrace(); - } + try (FileInputStream fip = new FileInputStream(path)) { + swearingConfigFile.load(fip); + } + } catch (IOException e2) { + e2.printStackTrace(); + } + } catch (IOException e) { + e.printStackTrace(); + } - ChatEvents.init(); - MinecraftForge.EVENT_BUS.register(new ChatEvents()); - } + return swearingConfigFile; + } } \ No newline at end of file diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..360983e --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,55 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="javafml" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the forge version +loaderVersion="[32,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. +# A URL to refer people to when problems occur with this mod +# issueTrackerURL="http://my.issue.tracker/" #optional +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="colecf_safechat" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +# ${file.jarVersion} didn't work for some reason +version="1.16.1" #mandatory + # A display name for the mod +displayName="Safechat" #mandatory +# A URL to query for updates for this mod. See the JSON update specification +# updateJSONURL="http://myurl.me/" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +displayURL="https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/1284263-safechat" #optional +# A file name (in the root of the mod JAR) containing a logo for display +logoFile="safechat_logo.png" #optional +# A text field displayed in the mod UI +# credits="Thanks for this example mod goes to Java" #optional +# A text field displayed in the mod UI +authors="Colecf" #optional +# The description text for the mod (multi line!) (#mandatory) +description=''' +A swear word filter for Minecraft. + +Thanks to Fokkusu on the Minecraft forums for the logo. +''' +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.examplemod]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[32,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.examplemod]] + modId="minecraft" + mandatory=true + versionRange="[1.16.1]" + ordering="NONE" + side="BOTH" diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info deleted file mode 100644 index 21ac68b..0000000 --- a/src/main/resources/mcmod.info +++ /dev/null @@ -1,19 +0,0 @@ -[ -{ -"modid": "colecf.Safechat", -"name": "Safechat", -"description": "Blocks swear words from multiplayer chat.", -"version": "1.10.2", -"credits": "", -"logoFile": "safechat_logo.png", -"mcversion": "1.10.2", -"url": "http://www.minecraftforum.net/topic/1314911-132-safechat/", -"updateUrl": "", -"authors": [ "Colecf" ], -"parent":"", -"screenshots": [], -"dependencies": [ - "mod_MinecraftForge" -] -} -] \ No newline at end of file diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..dff8325 --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,7 @@ +{ + "pack": { + "description": "Safechat resources", + "pack_format": 5, + "_comment": "A pack_format of 5 requires json lang files and some texture changes from 1.15. Note: we require v5 pack meta for all mods." + } +}