Skip to content

Commit

Permalink
httpclient dependency, emptybox, itemshout, pokeshoutall, showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
chasem-dev committed Jan 25, 2024
1 parent ac4300c commit 93d9253
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ tasks {
archiveBaseName.set("CobblemonExtras-${project.name}")
configurations = listOf(bundle)
mergeServiceFiles()
// include org.apache.httpcomponents:httpclient 4.4.1 in jar
// dependencies {
// include("org.apache.httpcomponents:httpclient:4.4.1")
// }

}

remapJar {
Expand Down
4 changes: 4 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ repositories {
dependencies {
implementation(libs.stdlib)
implementation(libs.reflect)
implementation(libs.httpclient)
// implementation(libs.shadow)
implementation ("org.apache.httpcomponents:httpclient:4.5.13")

modImplementation(libs.fabricLoader)
modApi ("curse.maven:cobblemon-687131:4797468")
// org.apache.http

//shadowCommon group: 'commons-io', name: 'commons-io', version: '2.6'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,36 @@

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import dev.chasem.cobblemonextras.CobblemonExtras;
import com.google.gson.annotations.SerializedName;

import java.io.*;
import java.lang.reflect.Type;
import java.util.HashMap;

public class CobblemonExtrasConfig {
Gson GSON = new GsonBuilder()

public static Gson GSON = new GsonBuilder()
.disableHtmlEscaping()
.setPrettyPrinting()
.create();
public static int COMMAND_POKETRADE_PERMISSION_LEVEL = 2;
public static int COMMAND_POKESEE_PERMISSION_LEVEL = 2;
public static int COMMAND_POKESEEOTHER_PERMISSION_LEVEL = 2;
public static int COMMAND_PC_PERMISSION_LEVEL = 2;
public static int COMMAND_POKESHOUT_PERMISSION_LEVEL = 2;
public static int COMMAND_COMPSEE_PERMISSION_LEVEL = 2;
public static int COMMAND_COMPSEEOTHER_PERMISSION_LEVEL = 2;
public static int COMMAND_POKEBATTLE_PERMISSION_LEVEL = 3;
public static int COMMAND_BATTLE_PERMISSION_LEVEL = 2;
public static int COMMAND_COMPTAKE_PERMISSION_LEVEL = 2;

public static int COMMAND_POKEIVS_PERMISSION_LEVEL = 2;
public static boolean SHOWCASE_ENABLED = true;

public CobblemonExtrasConfig() {
init();
}

public void init() {
File configFolder = new File(System.getProperty("user.dir") + "/config/cobblemonextras");
File configFile = new File(configFolder, "config.json");
System.out.println("CobblemonExtras config -> " + configFolder.getAbsolutePath());
if (!configFolder.exists()) {
configFolder.mkdirs();
createConfig(configFolder);
} else if (!configFile.exists()) {
createConfig(configFolder);
}

try {
Type type = new TypeToken<HashMap<String, Integer>>(){}.getType();
JsonObject obj = GSON.fromJson(new FileReader(configFile), JsonObject.class);
JsonObject permLevels = obj.get("permissionlevels").getAsJsonObject();
HashMap<String, Integer> permissionMap = GSON.fromJson(permLevels, type);

COMMAND_POKETRADE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.poketrade", 2);
COMMAND_POKESEE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokesee", 2);
COMMAND_POKESEEOTHER_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokeseeother", 2);
COMMAND_PC_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pc", 2);
COMMAND_POKESHOUT_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokeshout", 2);
COMMAND_COMPSEE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.compsee", 2);
COMMAND_COMPSEEOTHER_PERMISSION_LEVEL = permissionMap.getOrDefault("command.compseeother", 2);
COMMAND_BATTLE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.battle", 2);
COMMAND_POKEBATTLE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokebattle", 2);
COMMAND_COMPTAKE_PERMISSION_LEVEL = permissionMap.getOrDefault("command.comptake", 2);
COMMAND_POKEIVS_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokeivs", 2);

} catch (Exception e) {
throw new RuntimeException(e);
}
@SerializedName("permissionlevels") public PermissionLevels permissionLevels = new PermissionLevels();
public ShowcaseConfig showcase = new ShowcaseConfig();
public class PermissionLevels {
@SerializedName("command.poketrade") public int COMMAND_POKETRADE_PERMISSION_LEVEL = 2;
@SerializedName("command.pokesee") public int COMMAND_POKESEE_PERMISSION_LEVEL = 2;
@SerializedName("command.pokeseeother") public int COMMAND_POKESEEOTHER_PERMISSION_LEVEL = 2;
@SerializedName("command.pc") public int COMMAND_PC_PERMISSION_LEVEL = 2;
@SerializedName("command.pokeshout") public int COMMAND_POKESHOUT_PERMISSION_LEVEL = 2;
@SerializedName("command.itemshout") public int COMMAND_ITEMSHOUT_PERMISSION_LEVEL = 2;
@SerializedName("command.compsee") public int COMMAND_COMPSEE_PERMISSION_LEVEL = 2;
@SerializedName("command.compseeother") public int COMMAND_COMPSEEOTHER_PERMISSION_LEVEL = 2;
@SerializedName("command.pokebattle") public int COMMAND_POKEBATTLE_PERMISSION_LEVEL = 3;
@SerializedName("command.battle") public int COMMAND_BATTLE_PERMISSION_LEVEL = 2;
@SerializedName("command.comptake") public int COMMAND_COMPTAKE_PERMISSION_LEVEL = 2;
@SerializedName("command.pokeivs") public int COMMAND_POKEIVS_PERMISSION_LEVEL = 2;
@SerializedName("command.emptybox") public int COMMAND_EMPTYBOX_PERMISSION_LEVEL = 2;
@SerializedName("command.pokeshoutall") public int COMMAND_POKESHOUT_ALL_PERMISSION_LEVEL = 2;
}

private void createConfig(File configFolder) {
File file = new File(configFolder, "config.json");
try {
file.createNewFile();
JsonWriter writer = GSON.newJsonWriter(new FileWriter(file));
writer.beginObject()
.name("permissionlevels")
.beginObject()
.name("command.poketrade")
.value(2)
.name("command.pokesee")
.value(2)
.name("command.pokeseeother")
.value(2)
.name("command.pc")
.value(2)
.name("command.pokeshout")
.value(2)
.name("command.compsee")
.value(2)
.name("command.compseeother")
.value(2)
.name("command.battle")
.value(2)
.name("command.pokebattle")
.value(2)
.name("command.comptake")
.value(2)
.name("command.pokeivs")
.value(2)
.endObject()
.endObject()
.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
public class ShowcaseConfig {
public boolean isShowcaseEnabled = true;
public String apiSecret = "To start using showcase, please goto https://cobblemonextras.com/showcase";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.cobblemon.mod.common.Cobblemon;
import com.cobblemon.mod.common.api.permission.CobblemonPermission;
import com.cobblemon.mod.common.api.permission.PermissionLevel;
import dev.chasem.cobblemonextras.config.CobblemonExtrasConfig;
import dev.chasem.cobblemonextras.CobblemonExtras;
import net.minecraft.command.CommandSource;

public class CobblemonExtrasPermissions {
Expand All @@ -19,19 +19,25 @@ public class CobblemonExtrasPermissions {
public final CobblemonPermission BATTLE_PERMISSION;
public final CobblemonPermission COMPTAKE_PERMISSION;
public final CobblemonPermission POKEIVS_PERMISSION;
public final CobblemonPermission EMPTYBOX_PERMISSION;
public final CobblemonPermission POKESHOUT_ALL_PERMISSION;
public final CobblemonPermission ITEMSHOUT_PERMISSION;

public CobblemonExtrasPermissions() {
this.COMPSEE_PERMISSION = new CobblemonPermission("cobblemonextras.command.compsee", toPermLevel(CobblemonExtrasConfig.COMMAND_COMPSEE_PERMISSION_LEVEL));
this.COMPESEE_OTHER_PERMISSION = new CobblemonPermission("cobblemonextras.command.compseeother", toPermLevel(CobblemonExtrasConfig.COMMAND_COMPSEEOTHER_PERMISSION_LEVEL));
this.PC_PERMISSION = new CobblemonPermission("cobblemonextras.command.pc", toPermLevel(CobblemonExtrasConfig.COMMAND_PC_PERMISSION_LEVEL));
this.POKESEE_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokesee", toPermLevel(CobblemonExtrasConfig.COMMAND_POKESEE_PERMISSION_LEVEL));
this.POKESEE_OTHER_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeseeother", toPermLevel(CobblemonExtrasConfig.COMMAND_POKESEEOTHER_PERMISSION_LEVEL));
this.POKESHOUT_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeshout", toPermLevel(CobblemonExtrasConfig.COMMAND_POKESHOUT_PERMISSION_LEVEL));
this.POKETRADE_PERMISSION = new CobblemonPermission("cobblemonextras.command.poketrade", toPermLevel(CobblemonExtrasConfig.COMMAND_POKETRADE_PERMISSION_LEVEL));
this.POKEBATTLE_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokebattle", toPermLevel(CobblemonExtrasConfig.COMMAND_POKEBATTLE_PERMISSION_LEVEL));
this.BATTLE_PERMISSION = new CobblemonPermission("cobblemonextras.command.battle", toPermLevel(CobblemonExtrasConfig.COMMAND_BATTLE_PERMISSION_LEVEL));
this.COMPTAKE_PERMISSION = new CobblemonPermission("cobblemonextras.command.comptake", toPermLevel(CobblemonExtrasConfig.COMMAND_COMPTAKE_PERMISSION_LEVEL));
this.POKEIVS_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeivs", toPermLevel(CobblemonExtrasConfig.COMMAND_POKEIVS_PERMISSION_LEVEL));
this.COMPSEE_PERMISSION = new CobblemonPermission("cobblemonextras.command.compsee", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_COMPSEE_PERMISSION_LEVEL));
this.COMPESEE_OTHER_PERMISSION = new CobblemonPermission("cobblemonextras.command.compseeother", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_COMPSEEOTHER_PERMISSION_LEVEL));
this.PC_PERMISSION = new CobblemonPermission("cobblemonextras.command.pc", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_PC_PERMISSION_LEVEL));
this.POKESEE_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokesee", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKESEE_PERMISSION_LEVEL));
this.POKESEE_OTHER_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeseeother", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKESEEOTHER_PERMISSION_LEVEL));
this.POKESHOUT_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeshout", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKESHOUT_PERMISSION_LEVEL));
this.POKETRADE_PERMISSION = new CobblemonPermission("cobblemonextras.command.poketrade", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKETRADE_PERMISSION_LEVEL));
this.POKEBATTLE_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokebattle", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKEBATTLE_PERMISSION_LEVEL));
this.BATTLE_PERMISSION = new CobblemonPermission("cobblemonextras.command.battle", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_BATTLE_PERMISSION_LEVEL));
this.COMPTAKE_PERMISSION = new CobblemonPermission("cobblemonextras.command.comptake", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_COMPTAKE_PERMISSION_LEVEL));
this.POKEIVS_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeivs", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKEIVS_PERMISSION_LEVEL));
this.EMPTYBOX_PERMISSION = new CobblemonPermission("cobblemonextras.command.emptybox", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_EMPTYBOX_PERMISSION_LEVEL));
this.POKESHOUT_ALL_PERMISSION = new CobblemonPermission("cobblemonextras.command.pokeshoutall", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_POKESHOUT_ALL_PERMISSION_LEVEL));
this.ITEMSHOUT_PERMISSION = new CobblemonPermission("cobblemonextras.command.itemshout", toPermLevel(CobblemonExtras.config.permissionLevels.COMMAND_ITEMSHOUT_PERMISSION_LEVEL));
}

public PermissionLevel toPermLevel(int permLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.cobblemon.mod.common.api.storage.party.PlayerPartyStore;
import com.cobblemon.mod.common.api.storage.pc.PCBox;
import com.cobblemon.mod.common.api.storage.pc.PCStore;
import com.cobblemon.mod.common.config.CobblemonConfig;
import com.cobblemon.mod.common.pokemon.Pokemon;
import dev.chasem.cobblemonextras.util.ItemBuilder;
import dev.chasem.cobblemonextras.util.PokemonUtility;
Expand Down Expand Up @@ -101,7 +102,7 @@ public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity pl
return new GenericContainerScreenHandler(ScreenHandlerType.GENERIC_9X5, syncId, inv, inventory, rows()) {
@Override
public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) {
if (slotIndex == 44 && boxNumber < 29) {
if (slotIndex == 44 && boxNumber < Cobblemon.config.getDefaultBoxCount() - 1) {
player.openHandledScreen(new CompSeeHandlerFactory(toView, boxNumber + 1));
}
if (slotIndex == 42 && boxNumber > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Text getHoverText(MutableText toSend, Pokemon pokemon) {

MutableText ivsText = Text.literal(" [IVs]").formatted(Formatting.LIGHT_PURPLE);
MutableText ivsHoverText = Text.literal("");
List<Text> ivsHoverTextList = Text.literal("IVs").formatted(Formatting.GOLD).getWithStyle(Style.EMPTY.withUnderline(Boolean.TRUE));
List<Text> ivsHoverTextList = Text.literal("IVs").formatted(Formatting.LIGHT_PURPLE).getWithStyle(Style.EMPTY.withUnderline(Boolean.TRUE));
ivsHoverTextList.add(Text.literal("\n"));
ivsHoverTextList.add(Text.literal("HP: ").formatted(Formatting.RED).append(Text.literal(String.valueOf(pokemon.getIvs().getOrDefault(Stats.HP))).formatted(Formatting.WHITE)));
ivsHoverTextList.add(Text.literal("\n"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,79 @@ import com.mojang.brigadier.CommandDispatcher
import dev.chasem.cobblemonextras.commands.*
import dev.chasem.cobblemonextras.config.CobblemonExtrasConfig
import dev.chasem.cobblemonextras.permissions.CobblemonExtrasPermissions
import dev.chasem.cobblemonextras.services.ShowcaseService
import net.minecraft.command.CommandRegistryAccess
import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource
import java.io.File
import java.io.FileReader
import java.io.FileWriter
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


object CobblemonExtras {
public lateinit var permissions: CobblemonExtrasPermissions
const val MODID = "cobblemonextras"
lateinit var config: CobblemonExtrasConfig
var LOGGER: Logger = LogManager.getLogger("[CobblemonExtras]")
val showcaseService = ShowcaseService()

fun initialize() {
System.out.println("CobblemonExtras - Initialized")
CobblemonExtrasConfig() // must load before permissions so perms use default permission level.
loadConfig() // must load before permissions so perms use default permission level.
this.permissions = CobblemonExtrasPermissions()
showcaseService.init()
}

fun onShutdown() {
System.out.println("CobblemonExtras - Shutting Down")
showcaseService.stop();
}

public fun getLogger(): Logger {
return this.LOGGER;
}

fun loadConfig() {
val configFileLoc = System.getProperty("user.dir") + File.separator + "config" + File.separator + "cobblemonextras" + File.separator + "config.json";
System.out.println("Loading config file found at: $configFileLoc")
val configFile: File = File(configFileLoc)
configFile.parentFile.mkdirs()

// Check config existence and load if it exists, otherwise create default.
if (configFile.exists()) {
try {
val fileReader = FileReader(configFile)
config = CobblemonExtrasConfig.GSON.fromJson(fileReader, CobblemonExtrasConfig::class.java)
fileReader.close()
} catch (e: Exception) {
System.err.println("[CobblemonExtras] Failed to load the config! Using default config as fallback")
e.printStackTrace()
config = CobblemonExtrasConfig()
}
} else {
config = CobblemonExtrasConfig()
}
saveConfig()
}

private fun saveConfig() {
try {
val configFileLoc = System.getProperty("user.dir") + File.separator + "config" + File.separator + "cobblemonextras" + File.separator + "config.json";
System.out.println("Saving config to: $configFileLoc")
val configFile: File = File(configFileLoc)
val fileWriter = FileWriter(configFile)
CobblemonExtrasConfig.GSON.toJson(config, fileWriter)
fileWriter.flush()
fileWriter.close()
} catch (e: java.lang.Exception) {
System.err.println("[CobblemonExtras] Failed to save config")
e.printStackTrace()
}
}


fun registerCommands(
dispatcher: CommandDispatcher<ServerCommandSource>,
registry: CommandRegistryAccess,
Expand All @@ -34,6 +93,12 @@ object CobblemonExtras {
PokeBattle().register(dispatcher)
PCDelete().register(dispatcher)
PokeIVs().register(dispatcher)

PokeShoutAll().register(dispatcher)
EmptyBox().register(dispatcher)
PokeShoutAll().register(dispatcher)
Showcase().register(dispatcher)
ItemShout().register(dispatcher)
}

}
2 changes: 2 additions & 0 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation(project(":common", configuration = "namedElements")) {
isTransitive = false
}

"developmentFabric"(project(":common", configuration = "namedElements")) {
isTransitive = false
}
Expand All @@ -54,6 +55,7 @@ dependencies {
libs.jetbrainsAnnotations,
libs.serializationCore,
libs.serializationJson,
libs.httpclient
).forEach {
bundle(it)
runtimeOnly(it)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package dev.chasem.cobblemonextras.fabric

import com.cobblemon.mod.common.platform.events.PlatformEvents
import dev.chasem.cobblemonextras.CobblemonExtras
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents

class CobblemonFabric : ModInitializer {
override fun onInitialize() {
System.out.println("Fabric Mod init")
CobblemonExtras.initialize();
CommandRegistrationCallback.EVENT.register(CobblemonExtras::registerCommands)
ServerLifecycleEvents.SERVER_STOPPING.register { CobblemonExtras.onShutdown() }
}
}
8 changes: 6 additions & 2 deletions forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ dependencies {
libs.stdlib,
libs.serializationCore,
libs.serializationJson,
libs.reflect
).forEach(::forgeRuntimeLibrary)
libs.reflect,
libs.httpclient
).forEach {
bundle(it)
forgeRuntimeLibrary(it)
}
}

tasks {
Expand Down
Loading

0 comments on commit 93d9253

Please sign in to comment.