Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ItziSpyder authored Mar 8, 2023
1 parent 2ea822c commit c3ca5fe
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.19.3
yarn_mappings=1.19.3+build.5
loader_version=0.14.17
# Mod Properties
mod_version=1.19.3-0.1.0
mod_version=1.19.3-0.2.0
maven_group=io.github.itzispyder
archives_base_name=FunnySentences
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.itzispyder.funnysentences.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;

/**
* Command
*/
public abstract class Command {

public static final int SINGLE_SUCCESS = 1;
public static final int COMMAND_FAIL = -1;
public static final int COMMAND_PASS = 0;

/**
* On command run
* @param dispatcher command dispatcher
* @param access accessor
*/
public abstract void onCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access);

/**
* Command literal argument builder
* @param name name
* @return argument builder
*/
public static LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
return LiteralArgumentBuilder.literal(name);
}

/**
* Command required argument builder
* @param name name
* @param type argument type
* @return argument builder
* @param <T> argument object
*/
public static <T> RequiredArgumentBuilder<FabricClientCommandSource,T> argument(String name, ArgumentType<T> type) {
return RequiredArgumentBuilder.argument(name, type);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.itzispyder.funnysentences.commands;

import io.github.itzispyder.funnysentences.commands.commands.SentenceCommand;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.event.Event;

/**
* Commands registry
*/
public abstract class Commands {

/**
* Registers all the commands from this mod
*/
public static void registerAll() {
Event<ClientCommandRegistrationCallback> cmd = ClientCommandRegistrationCallback.EVENT;
cmd.register(new SentenceCommand()::onCommand);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.github.itzispyder.funnysentences.commands.commands;

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import io.github.itzispyder.funnysentences.commands.Command;
import io.github.itzispyder.funnysentences.data.sentences.SentenceConstructor;
import io.github.itzispyder.funnysentences.data.sentences.SentenceFeature;
import io.github.itzispyder.funnysentences.data.sentences.SentenceGenerator;
import io.github.itzispyder.funnysentences.util.ChatUtils;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;

import static io.github.itzispyder.funnysentences.FunnySentences.starter;

public class SentenceCommand extends Command {

@Override
public void onCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) {
// fs
dispatcher.register(literal("fs").executes(cxt -> {
SentenceFeature feature = new SentenceFeature();
String sentence = SentenceConstructor.generate(SentenceGenerator.NORMAL,feature);
ChatUtils.sendChatMessage(sentence);
return SINGLE_SUCCESS;
}));
for (SentenceGenerator gen : SentenceGenerator.values()) {
// fs <type>
dispatcher.register(literal("fs").then(literal(gen.name().toLowerCase()).executes(cxt -> {
SentenceFeature feature = new SentenceFeature();
String sentence = SentenceConstructor.generate(gen, feature);
ChatUtils.sendChatMessage(sentence);
return SINGLE_SUCCESS;
})));
// fs <type> spam <times>
dispatcher.register(literal("fs").then(literal(gen.name().toLowerCase()).then(literal("spam").then(argument("times", IntegerArgumentType.integer()).executes(cxt -> {
int times = cxt.getArgument("times",Integer.class);
SentenceFeature feature = new SentenceFeature();
for (int i = 0; i < times; i++) {
String sentence = SentenceConstructor.generate(gen, feature);
ChatUtils.sendChatMessage(sentence);
}
return SINGLE_SUCCESS;
})))));
// fs <type> words <count>
dispatcher.register(literal("fs").then(literal(gen.name().toLowerCase()).then(literal("words").then(argument("count", IntegerArgumentType.integer()).executes(cxt -> {
int count = cxt.getArgument("count",Integer.class);
SentenceFeature feature = new SentenceFeature();
feature.setWordCount(count);
String sentence = SentenceConstructor.generate(gen, feature);
ChatUtils.sendChatMessage(sentence);
return SINGLE_SUCCESS;
})))));
// fs <type> words <count> spam <times>
dispatcher.register(literal("fs").then(literal(gen.name().toLowerCase()).then(literal("words").then(argument("count", IntegerArgumentType.integer()).then(literal("spam").then(argument("times",IntegerArgumentType.integer()).executes(cxt -> {
int count = cxt.getArgument("count",Integer.class);
int times = cxt.getArgument("times",Integer.class);
SentenceFeature feature = new SentenceFeature();
feature.setWordCount(count);
for (int i = 0; i < times; i++) {
String sentence = SentenceConstructor.generate(gen, feature);
ChatUtils.sendChatMessage(sentence);
}
return SINGLE_SUCCESS;
})))))));
}
// fs spam <times>
dispatcher.register(literal("fs").then(literal("spam").then(argument("times",IntegerArgumentType.integer()).then(argument("message", StringArgumentType.greedyString()).executes(cxt -> {
int times = cxt.getArgument("times",Integer.class);
String message = cxt.getArgument("message",String.class);
for (int i = 0; i < times; i++) ChatUtils.sendChatMessage(message);
return SINGLE_SUCCESS;
})))));
// fs help
dispatcher.register(literal("fs").then(literal("help").executes(cxt -> {
ChatUtils.sendMessage(
"",
starter + "§bThe Ultimate Chat Spam Troll",
" §f/fs §8| §7Send random sentence",
" §f/fs §e<type> §8| §7Sends sentences",
" §f/fs §e<type> §fspam §e<times> §8| §7Spams sentences",
" §f/fs §e<type> §fword §e<amount> §8| §7Sends sentences with custom word count",
" §f/fs §e<type> §fword §e<amount> §fspam §e<times> §8| §7Spams sentences with custom word count",
" §f/fs spam §e<times> <message> §8| §7Spams custom message",
" §f/fs help §8| §7Command help",
""
);
return SINGLE_SUCCESS;
})));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ private static String custom(SentenceGenerator type, SentenceFeature feature) {
StringBuilder word = new StringBuilder();
for (int j = 0; j < wordLength; j++) {
switch (type) {
case LETTER_SPAM -> word.append(new Randomizer<>(DefaultSentenceComponents.ALPHABET).pickRand());
case EMOJI_SPAM -> word.append(new Randomizer<>(DefaultSentenceComponents.EMOJIS).pickRand());
case UNICODE_SPAM -> word.append(new Randomizer<>(DefaultSentenceComponents.UNICODES).pickRand());
case RAGE -> word.append(new Randomizer<>(DefaultSentenceComponents.ALPHABET).pickRand());
case EMOJI -> word.append(new Randomizer<>(DefaultSentenceComponents.EMOJIS).pickRand());
case UNICODE -> word.append(new Randomizer<>(DefaultSentenceComponents.UNICODES).pickRand());
}
}
sentence.append(word).append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public enum SentenceGenerator {

NORMAL,
UNICODE_SPAM,
LETTER_SPAM,
EMOJI_SPAM
UNICODE,
RAGE,
EMOJI
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public abstract class ChatUtils {
*/
public static void sendChatMessage(String message) {
if (message == null) return;
if (message.startsWith("/")) return;
mc.player.networkHandler.sendChatMessage(message);
}

Expand All @@ -27,4 +26,12 @@ public static void sendMessage(String message) {
if (message == null) return;
mc.player.sendMessage(Text.literal(message));
}

/**
* Sends a series of chat messages to the player
* @param messages messages to send
*/
public static void sendMessage(String... messages) {
for (String message : messages) sendMessage(message);
}
}

0 comments on commit c3ca5fe

Please sign in to comment.