From df9041dc05e1e159d7878d1db960440a2d00b9ed Mon Sep 17 00:00:00 2001 From: Thomas Truong Date: Sun, 16 Apr 2023 17:01:03 -0700 Subject: [PATCH] Added VIP settings. --- README.md | 52 ++++++++++--------- .../commands/PokeBreed.java | 45 +++++++++++++--- .../VeryScuffedCobblemonBreedingConfig.java | 15 ++++-- ...ryScuffedCobblemonBreedingPermissions.java | 2 + gradle.properties | 2 +- 5 files changed, 80 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index a01548f..ee97d89 100644 --- a/README.md +++ b/README.md @@ -4,28 +4,28 @@ My attempt to create a scuffed Cobblemon "breeding" for my friends and I to use. - It is an instant breeding system with a 5 minute default cooldown. - Can only breed Cobblemons from your PC. - Single player cooldown has a slight issue. - - If you rejoin, you are instantly out of cooldown. - - Cheat at your own will. + - If you rejoin, you are instantly out of cooldown. + - Cheat at your own will. - Tries to mimic the actual breeding system. - - Can breed using ditto, self, or same egg groups. - - Offspring will be the same as the mother. - - Offspring is the base evolution. - - Moves and EXP are reset. - - 1/8192 chance to get a shiny. - - Also has the breeding restrictions. - - No same genders. - - No differing egg groups. - - No Undiscovered egg group. - - No double ditto. - - 3 IVs randomly get inherited from either parent. - - Unless breeding items come out. - - EVs get reset. - - Nature gets RNG'd since no Everstone in the game currently. - - Friendship gets randomized. - - Gender gets randomized based on the Cobblemon's gender ratio. - - Ability gets randomized. - - Hidden abilities are supported. - - 60% chance to pass down if either parents have a hidden ability. + - Can breed using ditto, self, or same egg groups. + - Offspring will be the same as the mother. + - Offspring is the base evolution. + - Moves and EXP are reset. + - 1/8192 chance to get a shiny. + - Also has the breeding restrictions. + - No same genders. + - No differing egg groups. + - No Undiscovered egg group. + - No double ditto. + - 3 IVs randomly get inherited from either parent. + - Unless breeding items come out. + - EVs get reset. + - Nature gets RNG'd since no Everstone in the game currently. + - Friendship gets randomized. + - Gender gets randomized based on the Cobblemon's gender ratio. + - Ability gets randomized. + - Hidden abilities are supported. + - 60% chance to pass down if either parents have a hidden ability. ## Download [Latest](https://github.com/ThomasQTruong/VeryScuffedCobblemonBreeding/releases/tag/1.0.0) @@ -37,7 +37,7 @@ My attempt to create a scuffed Cobblemon "breeding" for my friends and I to use. 2. Select two Cobblemons to breed. - ![image](https://user-images.githubusercontent.com/58405482/232265199-6c2311e6-e348-41be-a984-3d6a79b6dc5d.png) - Next/Previous box is at the bottom right. - - ![image](https://user-images.githubusercontent.com/58405482/232265149-941782aa-e863-4c98-91ba-5c1616c3f6b6.png) + - ![image](https://user-images.githubusercontent.com/58405482/232265149-941782aa-e863-4c98-91ba-5c1616c3f6b6.png) 3. Confirm breed. - Confirmation button is between the Next/Previous buttons. - ![image](https://user-images.githubusercontent.com/58405482/232265217-2b3493e5-272d-43d8-b7b3-49dd284f98da.png) @@ -46,9 +46,11 @@ My attempt to create a scuffed Cobblemon "breeding" for my friends and I to use. ## Configs ### Permissions -- command.pokebreed - default is permission level 2. +- command.pokebreed - default for MC is level 2. +- command.vippokebreed - permission for to get VIP cooldown. ### Cooldowns - command.pokebreed.cooldown - default is 5 minutes. +- command.pokebreed.vipcooldown - default is 3 minutes. ## Credits This would not have been possible without these open source works: @@ -58,6 +60,6 @@ This would not have been possible without these open source works: ## Addons used in images: Datapacks - [Cardboard Cutout Mon](https://modrinth.com/resourcepack/cardboard-cutout-mon) by [EikoBiko](https://modrinth.com/user/EikoBiko) - - Adds cardboard cutout textures for Cobblemons that do not have a model yet. + - Adds cardboard cutout textures for Cobblemons that do not have a model yet. - [Questionably Lore Accurate Pokemon Spawns](https://modrinth.com/datapack/questionably-lore-accurate-pokemon-spawns) by [FrankTheFarmer2](https://modrinth.com/user/FrankTheFarmer2) - - Adds spawn files for some Cobblemons that do not have a model yet. + - Adds spawn files for some Cobblemons that do not have a model yet. diff --git a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/commands/PokeBreed.java b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/commands/PokeBreed.java index 044e99d..35b11d9 100644 --- a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/commands/PokeBreed.java +++ b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/commands/PokeBreed.java @@ -52,6 +52,11 @@ public void register(CommandDispatcher dispatcher) { .requires(src -> VeryScuffedCobblemonBreedingPermissions.checkPermission(src, VeryScuffedCobblemonBreeding.permissions.POKEBREED_PERMISSION)) .executes(this::execute) ); + dispatcher.register( + literal("pokebreed") + .requires(src -> VeryScuffedCobblemonBreedingPermissions.checkPermission(src, VeryScuffedCobblemonBreeding.permissions.VIP_POKEBREED_PERMISSION)) + .executes(this::execute) + ); // Set up scheduler. scheduler = new ScheduledThreadPoolExecutor(1, r -> { Thread thread = Executors.defaultThreadFactory().newThread(r); @@ -66,6 +71,9 @@ public void register(CommandDispatcher dispatcher) { private int execute(CommandContext ctx) { if (ctx.getSource().getPlayer() != null) { ServerPlayerEntity player = ctx.getSource().getPlayer(); + // Checks whether player has VIP permissions. + boolean isVIP = VeryScuffedCobblemonBreedingPermissions.checkPermission(ctx.getSource(), + VeryScuffedCobblemonBreeding.permissions.VIP_POKEBREED_PERMISSION); // Breed session already exists for player. if (breedSessions.containsKey(player.getUuid())) { @@ -79,9 +87,18 @@ private int execute(CommandContext ctx) { // Pokemon was bred before; check if it never got off cooldown. long timeSince = System.currentTimeMillis() - breedSession.timeBred; - // Cooldown was supposed to be over! - if (timeSince > 1000L * 60 * VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES) { - breedSessions.remove(player.getUuid()); + // User is a VIP. + if (isVIP) { + // Cooldown was supposed to be over! + if (timeSince > 1000L * 60 * VeryScuffedCobblemonBreedingConfig.VIP_COOLDOWN_IN_MINUTES) { + breedSessions.remove(player.getUuid()); + } + } else { + // User is not a VIP. + // Cooldown was supposed to be over! + if (timeSince > 1000L * 60 * VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES) { + breedSessions.remove(player.getUuid()); + } } } } @@ -92,7 +109,11 @@ private int execute(CommandContext ctx) { BreedSession breedSession = breedSessions.get(player.getUuid()); long cooldownDuration = (System.currentTimeMillis() - breedSession.timeBred) / 1000; // Total cooldown time - time since = time left. - cooldownDuration = (VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES * 60L) - cooldownDuration; + if (isVIP) {; + cooldownDuration = (VeryScuffedCobblemonBreedingConfig.VIP_COOLDOWN_IN_MINUTES * 60L) - cooldownDuration; + } else { + cooldownDuration = (VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES * 60L) - cooldownDuration; + } Text toSend = Text.literal("Breed cooldown: " + cooldownDuration + " seconds.").formatted(Formatting.RED); player.sendMessage(toSend); @@ -102,6 +123,7 @@ private int execute(CommandContext ctx) { // Create and start breeding session. BreedSession breedSession = new BreedSession(player); + breedSession.isVIP = isVIP; breedSessions.put(player.getUuid(), breedSession); breedSession.start(); } @@ -120,6 +142,7 @@ public class BreedSession { public boolean changePage = false; public boolean dittoOrSelfBreeding = false; UUID breederUUID; + boolean isVIP = false; // Used to generate random numbers in functions. Random RNG = new Random(); @@ -187,9 +210,17 @@ public void doBreed() { // Send success message and set cooldown. Text toSend = Text.literal("Breed complete!").formatted(Formatting.GREEN); breeder.sendMessage(toSend); - scheduler.schedule(() -> { - breedSessions.remove(breederUUID); - }, VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES, TimeUnit.MINUTES); + // Player has VIP status. + if (isVIP) { + scheduler.schedule(() -> { + breedSessions.remove(breederUUID); + }, VeryScuffedCobblemonBreedingConfig.VIP_COOLDOWN_IN_MINUTES, TimeUnit.MINUTES); + } else { + // Player does not have VIP status. + scheduler.schedule(() -> { + breedSessions.remove(breederUUID); + }, VeryScuffedCobblemonBreedingConfig.COOLDOWN_IN_MINUTES, TimeUnit.MINUTES); + } timeBred = System.currentTimeMillis(); } else { cancel("One of the Cobblemons does not exist!"); diff --git a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/config/VeryScuffedCobblemonBreedingConfig.java b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/config/VeryScuffedCobblemonBreedingConfig.java index 67257e5..bd8b01d 100644 --- a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/config/VeryScuffedCobblemonBreedingConfig.java +++ b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/config/VeryScuffedCobblemonBreedingConfig.java @@ -17,13 +17,16 @@ public class VeryScuffedCobblemonBreedingConfig { .disableHtmlEscaping() .setPrettyPrinting() .create(); - public static int COMMAND_POKEBREED_PERMISSION_LEVEL = 2; - public static int COOLDOWN_IN_MINUTES = 5; // Default: 5 minutes cooldown. + public static int COMMAND_POKEBREED_PERMISSION_LEVEL = 2; // Default for MC is 2. + public static int VIP_COMMAND_POKEBREED_PERMISSION_LEVEL = 3; // VIP permission level. + public static int COOLDOWN_IN_MINUTES = 5; // Default: 5 minutes cooldown. + public static int VIP_COOLDOWN_IN_MINUTES = 3; // VIP breeding cooldown, default: 3. public VeryScuffedCobblemonBreedingConfig() { init(); } + // Extracts data from the config file. public void init() { File configFolder = new File(System.getProperty("user.dir") + "/config/veryscuffedcobblemonbreeding"); File configFile = new File(configFolder, "config.json"); @@ -38,7 +41,7 @@ public void init() { try { Type type = new TypeToken>(){}.getType(); JsonObject obj = GSON.fromJson(new FileReader(configFile), JsonObject.class); - + JsonObject permLevels = obj.get("permissionlevels").getAsJsonObject(); HashMap permissionMap = GSON.fromJson(permLevels, type); @@ -46,7 +49,9 @@ public void init() { HashMap cooldownsMap = GSON.fromJson(cooldowns, type); COMMAND_POKEBREED_PERMISSION_LEVEL = permissionMap.getOrDefault("command.pokebreed", 2); + VIP_COMMAND_POKEBREED_PERMISSION_LEVEL = permissionMap.getOrDefault("command.vippokebreed", 3); COOLDOWN_IN_MINUTES = cooldownsMap.getOrDefault("command.pokebreed.cooldown", 5); + VIP_COOLDOWN_IN_MINUTES = cooldownsMap.getOrDefault("command.pokebreed.vipcooldown", 3); } catch (Exception e) { throw new RuntimeException(e); @@ -63,11 +68,15 @@ private void createConfig(File configFolder) { .beginObject() .name("command.pokebreed") .value(COMMAND_POKEBREED_PERMISSION_LEVEL) + .name("command.vippokebreed") + .value(VIP_COMMAND_POKEBREED_PERMISSION_LEVEL) .endObject() .name("cooldowns") .beginObject() .name("command.pokebreed.cooldown") .value(COOLDOWN_IN_MINUTES) + .name("command.pokebreed.vipcooldown") + .value(VIP_COOLDOWN_IN_MINUTES) .endObject() .endObject() .flush(); diff --git a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/permissions/VeryScuffedCobblemonBreedingPermissions.java b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/permissions/VeryScuffedCobblemonBreedingPermissions.java index e0e19be..111c4b0 100644 --- a/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/permissions/VeryScuffedCobblemonBreedingPermissions.java +++ b/common/src/main/java/dev/thomasqtruong/veryscuffedcobblemonbreeding/permissions/VeryScuffedCobblemonBreedingPermissions.java @@ -9,9 +9,11 @@ public class VeryScuffedCobblemonBreedingPermissions { public final CobblemonPermission POKEBREED_PERMISSION; + public final CobblemonPermission VIP_POKEBREED_PERMISSION; public VeryScuffedCobblemonBreedingPermissions() { this.POKEBREED_PERMISSION = new CobblemonPermission("veryscuffedcobblemonbreeding.command.pokebreed", toPermLevel(VeryScuffedCobblemonBreedingConfig.COMMAND_POKEBREED_PERMISSION_LEVEL)); + this.VIP_POKEBREED_PERMISSION = new CobblemonPermission("veryscuffedcobblemonbreeding.command.vippokebreed", toPermLevel(VeryScuffedCobblemonBreedingConfig.VIP_COMMAND_POKEBREED_PERMISSION_LEVEL)); } public PermissionLevel toPermLevel(int permLevel) { diff --git a/gradle.properties b/gradle.properties index 8820afc..4cef5ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,5 +11,5 @@ luckperms_version=5.4 mod_id=veryscuffedcobblemonbreeding -mod_version=1.0.0 +mod_version=1.0.1 snapshot=false \ No newline at end of file