Skip to content

Commit

Permalink
add onLoggingIn tip(config default false)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyuxc-unknow committed Jan 23, 2024
1 parent 2b87a89 commit c2ccb63
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ minecraft_version=1.20.4
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.4,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.4.96-beta
neo_version=20.4.124-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[20.4,)
# The loader version range can only use the major version of FML as bounds
Expand All @@ -32,7 +32,7 @@ mod_name=Jrrp
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
mod_version=NeoForge-1.0.0
mod_version=1.0.0-NeoForge
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
57 changes: 33 additions & 24 deletions src/main/java/mod/lyuxc/Jrrp.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.neoforged.fml.config.ModConfig;
import net.neoforged.neoforge.common.ModConfigSpec;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;

import java.util.Calendar;
import java.util.List;
Expand All @@ -23,44 +24,52 @@ public class Jrrp {
private static ModConfigSpec.ConfigValue<List<? extends String>> PROMPT_WORD_LOW;
private static ModConfigSpec.ConfigValue<List<? extends String>> PROMPT_WORD_HIGH;
private static ModConfigSpec.ConfigValue<List<? extends String>> PROMPT_WORD_HIGHEST;
private static ModConfigSpec.ConfigValue<Boolean> ON_LOGGING_TIP;
private static final Calendar CALENDAR = Calendar.getInstance();
private static final String DAY_OF_YEAR = String.valueOf(CALENDAR.get(Calendar.DAY_OF_YEAR));
private static final RandomSource RANDOM_SOURCE = RandomSource.create();
private static String tipsText;
private static int JrrpValue = 0;

public Jrrp() {
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
tip = builder.define("Jrrp提示:","今日人品为:$v $w");
PROMPT_WORD_LOW = builder.defineList("提示词[0-50]",List.of(""),obj -> true);
PROMPT_WORD_HIGH = builder.defineList("提示词[51-90]",List.of(""),obj -> true);
PROMPT_WORD_HIGHEST = builder.defineList("提示词[91-100]",List.of(""),obj -> true);
ON_LOGGING_TIP = builder.define("进入时是否自动提示",false);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, builder.build());
}
@SubscribeEvent
public static void register(RegisterCommandsEvent event) {
event.getDispatcher().register(Commands.literal("jrrp")
.executes(context -> {
ServerPlayer player = context.getSource().getPlayerOrException();
CompoundTag compoundTag = player.getPersistentData();
if ((compoundTag.get("jrrpLaseTime") == null || compoundTag.get("jrrp") == null) || (!Objects.requireNonNull(compoundTag.get("jrrpLaseTime")).getAsString().equals(DAY_OF_YEAR))) {
player.getPersistentData().putString("jrrpLaseTime", DAY_OF_YEAR);
player.getPersistentData().putString("jrrp", String.valueOf(RANDOM_SOURCE.nextInt(101)));
compoundTag.putString("jrrpLaseTime", DAY_OF_YEAR);
compoundTag.putString("jrrp", String.valueOf(RANDOM_SOURCE.nextInt(101)));
player.save(compoundTag);
}
JrrpValue = Integer.parseInt(Objects.requireNonNull(compoundTag.get("jrrp")).getAsString());
if (JrrpValue < 50) {
tipsText = tip.get().replace("$w",PROMPT_WORD_LOW.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_LOW.get().size())));
} else if(JrrpValue < 90) {
tipsText = tip.get().replace("$w",PROMPT_WORD_HIGH.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_HIGH.get().size())));
} else {
tipsText = tip.get().replace("$w",PROMPT_WORD_HIGHEST.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_HIGHEST.get().size())));
}
tipsText=tipsText.replace("$v",String.valueOf(JrrpValue));
player.sendSystemMessage(Component.literal(tipsText));
return 0;
})
.executes(context -> JrrpEvent(context.getSource().getPlayerOrException()))
);
}

@SubscribeEvent
public static void PlayerLogging(PlayerEvent.PlayerLoggedInEvent event) {
if(ON_LOGGING_TIP.get()) JrrpEvent((ServerPlayer) event.getEntity());
}

public static int JrrpEvent(ServerPlayer player) {
CompoundTag compoundTag = player.getPersistentData();
if ((compoundTag.get("jrrpLaseTime") == null || compoundTag.get("jrrp") == null) || (!Objects.requireNonNull(compoundTag.get("jrrpLaseTime")).getAsString().equals(DAY_OF_YEAR))) {
player.getPersistentData().putString("jrrpLaseTime", DAY_OF_YEAR);
player.getPersistentData().putString("jrrp", String.valueOf(RANDOM_SOURCE.nextInt(101)));
compoundTag.putString("jrrpLaseTime", DAY_OF_YEAR);
compoundTag.putString("jrrp", String.valueOf(RANDOM_SOURCE.nextInt(101)));
player.save(compoundTag);
}
int jrrpValue = Integer.parseInt(Objects.requireNonNull(compoundTag.get("jrrp")).getAsString());
String tipsText;
if (jrrpValue < 50) {
tipsText = tip.get().replace("$w",PROMPT_WORD_LOW.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_LOW.get().size())));
} else if(jrrpValue < 90) {
tipsText = tip.get().replace("$w",PROMPT_WORD_HIGH.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_HIGH.get().size())));
} else {
tipsText = tip.get().replace("$w",PROMPT_WORD_HIGHEST.get().get(RANDOM_SOURCE.nextInt(PROMPT_WORD_HIGHEST.get().size())));
}
tipsText = tipsText.replace("$v",String.valueOf(jrrpValue));
player.displayClientMessage(Component.literal(tipsText),false);
return 0;
}
}

0 comments on commit c2ccb63

Please sign in to comment.