Skip to content

Commit

Permalink
Added VIP settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasQTruong committed Apr 17, 2023
1 parent e9c2400 commit df9041d
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 36 deletions.
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public void register(CommandDispatcher<ServerCommandSource> 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);
Expand All @@ -66,6 +71,9 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher) {
private int execute(CommandContext<ServerCommandSource> 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())) {
Expand All @@ -79,9 +87,18 @@ private int execute(CommandContext<ServerCommandSource> 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());
}
}
}
}
Expand All @@ -92,7 +109,11 @@ private int execute(CommandContext<ServerCommandSource> 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);
Expand All @@ -102,6 +123,7 @@ private int execute(CommandContext<ServerCommandSource> ctx) {

// Create and start breeding session.
BreedSession breedSession = new BreedSession(player);
breedSession.isVIP = isVIP;
breedSessions.put(player.getUuid(), breedSession);
breedSession.start();
}
Expand All @@ -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();

Expand Down Expand Up @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -38,15 +41,17 @@ public void init() {
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);

JsonObject cooldowns = obj.get("cooldowns").getAsJsonObject();
HashMap<String, Integer> 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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ luckperms_version=5.4


mod_id=veryscuffedcobblemonbreeding
mod_version=1.0.0
mod_version=1.0.1
snapshot=false

0 comments on commit df9041d

Please sign in to comment.