Skip to content

Commit

Permalink
+ 功能:使用指令添加生物黑白名单
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Dec 26, 2023
1 parent 3157fe8 commit 2b76ea2
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 32 deletions.
15 changes: 12 additions & 3 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ repositories {
mavenCentral()
maven { url 'https://maven.nova-committee.cn/releases' }
maven { url 'https://maven.mohistmc.com/' }

mavenLocal()
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()
forge "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
implementation forgeRuntimeLibrary(include("cn.evole.config:AtomConfig-Toml:${project.toml_version}"))
implementation forgeRuntimeLibrary(include("cn.evole.config:AtomConfig-Toml:${project.toml_version}")) {
transitive = false
}

compileOnly "net.luckperms:api:${lickperms_version}"
compileOnly "org.projectlombok:lombok:${lombok_version}"
Expand All @@ -39,8 +41,15 @@ remapJar {


tasks.register('copyJars', Copy) {
from "$projectDir/build/libs"
delete fileTree("$rootDir/build/libs").matching {
include "**/*.jar"
}
delete fileTree("$projectDir/build/libs").matching {
include "**/*.jar"
}
into "$rootDir/build/libs"
from("$projectDir/build/libs")
include { details -> details.file.name.contains("${mod_version}") }
}

buildNeeded.finalizedBy("copyJars")
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ org.gradle.daemon=false
mod_id=atomsweep
mod_name=AtomSweep-forge
mod_license=GPL V3
mod_version=0.2.0
mod_version=0.2.1
mod_group_id=committee.nova.atom
mod_authors=cnlimiter
mod_description=Example mod description.\nNewline characters can be used and will be replaced properly.
# Dependency Properties
minecraft_version=1.20.1
toml_version=0.1.2
toml_version=0.1.3
lombok_version=1.18.24
lickperms_version=5.4
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import lombok.val;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.ResourceLocationArgument;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistries;
import nova.committee.atom.sweep.Static;
import nova.committee.atom.sweep.core.Sweeper;
Expand Down Expand Up @@ -51,42 +54,98 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.then(
Commands.literal("white")
.then(
Commands.literal("add")
.executes(SweepCommand::whiteAdd)
.requires(context -> context.hasPermission(2))

Commands.literal("item")
.then(
Commands.literal("add")
.executes(SweepCommand::itemWhiteAdd)
.requires(context -> context.hasPermission(2))

)
.then(
Commands.literal("del")
.executes(SweepCommand::itemWhiteDel)
.requires(context -> context.hasPermission(2))
)
)
.then(
Commands.literal("del")
.executes(SweepCommand::whiteDel)
.requires(context -> context.hasPermission(2))
Commands.literal("entity")
.then(
Commands.literal("add")
.then(Commands.argument("entity_name", ResourceLocationArgument.id())
.executes(SweepCommand::entityWhiteAdd)
)
.requires(context -> context.hasPermission(2))

)
.then(
Commands.literal("del")
.then(Commands.argument("entity_name", ResourceLocationArgument.id())
.executes(SweepCommand::entityWhiteDel)
)
.requires(context -> context.hasPermission(2))
)
)

)
);
}

private static int whiteAdd(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
private static int itemWhiteAdd(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
val player = context.getSource().getPlayerOrException();
val itemStack = player.getMainHandItem();
if (ForgeRegistries.ITEMS.getKey(itemStack.getItem()) != null) {
ModConfig.INSTANCE.getItem().addItemEntitiesWhitelist(ForgeRegistries.ITEMS.getKey(itemStack.getItem()).toString());
ModConfig.INSTANCE.save();
Static.sendMessage(player, "message.cmd.white.add.success");
Static.sendMessage(player, "message.cmd.item_white.add.success");
} else {
Static.sendMessage(player, "message.cmd.white.add.fail");
Static.sendMessage(player, "message.cmd.item_white.add.fail");
}
return 1;
}

private static int whiteDel(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
private static int itemWhiteDel(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
val player = context.getSource().getPlayerOrException();
val itemStack = player.getMainHandItem();
if (ForgeRegistries.ITEMS.getKey(itemStack.getItem()) != null) {
ModConfig.INSTANCE.getItem().delItemEntitiesWhitelist(ForgeRegistries.ITEMS.getKey(itemStack.getItem()).toString());
ModConfig.INSTANCE.save();
Static.sendMessage(player, "message.cmd.white.del.success");
Static.sendMessage(player, "message.cmd.item_white.del.success");
} else {
Static.sendMessage(player, "message.cmd.item_white.del.success");
}
return 1;
}

private static int entityWhiteAdd(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
val player = context.getSource().getPlayerOrException();
val entityName = context.getArgument("entity_name", ResourceLocation.class);
//#if MC >= 11900
if (ForgeRegistries.ENTITY_TYPES.getValue(entityName) != null) {
//#else
//$$ if (ForgeRegistries.ENTITIES.getValue(entityName) != null) {
//#endif
ModConfig.INSTANCE.getMob().addMobEntitiesWhitelist(entityName.toString());
ModConfig.INSTANCE.save();
Static.sendMessage(player, "message.cmd.entity_white.add.success");
} else {
Static.sendMessage(player, "message.cmd.entity_white.add.fail");
}
return 1;
}

private static int entityWhiteDel(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
val player = context.getSource().getPlayerOrException();
val entityName = context.getArgument("entity_name", ResourceLocation.class);
//#if MC >= 11900
if (ForgeRegistries.ENTITY_TYPES.getValue(entityName) != null) {
//#else
//$$ if (ForgeRegistries.ENTITIES.getValue(entityName) != null) {
//#endif
ModConfig.INSTANCE.getItem().delItemEntitiesWhitelist(entityName.toString());
ModConfig.INSTANCE.save();
Static.sendMessage(player, "message.cmd.entity_white.del.success");
} else {
Static.sendMessage(player, "message.cmd.white.del.success");
Static.sendMessage(player, "message.cmd.entity_white.del.success");
}
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public ASMob(Mob entity) {
}

public boolean filtrate() {
int index;
if (ModConfig.INSTANCE.getMob().isMobWhiteMode()) {
// Whitelist
for (String s : ModConfig.INSTANCE.getMob().getMobEntitiesWhitelist()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.evole.config.toml.AutoLoadTomlConfig;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import org.tomlj.TomlTable;

/**
* Name: atomsweep / CommonConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.evole.config.toml.AutoLoadTomlConfig;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import org.tomlj.TomlTable;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.evole.config.toml.AutoLoadTomlConfig;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import org.tomlj.TomlTable;

import java.util.Arrays;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cn.evole.config.toml.TomlUtil;
import cn.evole.config.toml.annotation.Reload;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import org.tomlj.TomlTable;
import lombok.Getter;
import lombok.Setter;
import nova.committee.atom.sweep.Static;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.evole.config.toml.AutoLoadTomlConfig;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import org.tomlj.TomlTable;

/**
* Name: atomsweep / OthersConfig
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/assets/atomsweep/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"message.atomclean.mobCleanupComplete": "{0} mob entity(entities) removed",
"message.atomclean.monsterCleanupComplete": "{0} monster entity(entities) removed",
"message.atomclean.animalCleanupComplete": "{0} animal entity(entities) removed",
"message.cmd.white.add.success": "",
"message.cmd.white.add.fail": "",
"message.cmd.white.del.success": "",
"message.cmd.white.del.fail": ""
"message.cmd.item_white.add.success": "",
"message.cmd.item_white.add.fail": "",
"message.cmd.item_white.del.success": "",
"message.cmd.item_white.del.fail": "",
"message.cmd.entity_white.add.success": "",
"message.cmd.entity_white.add.fail": "",
"message.cmd.entity_white.del.success": "",
"message.cmd.entity_white.del.fail": ""
}
12 changes: 8 additions & 4 deletions src/main/resources/assets/atomsweep/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
"message.atomclean.mobCleanupComplete": "已清除 {0} 个生物实体。",
"message.atomclean.monsterCleanupComplete": "已清除 {0} 个怪物实体。",
"message.atomclean.animalCleanupComplete": "已清除 {0} 个动物实体。",
"message.cmd.white.add.success": "已经添加到白名单",
"message.cmd.white.add.fail": "添加到白名单失败",
"message.cmd.white.del.success": "已经从白名单移除",
"message.cmd.white.del.fail": "从白名单移除失败"
"message.cmd.item_white.add.success": "已经添加到白名单",
"message.cmd.item_white.add.fail": "添加到白名单失败",
"message.cmd.item_white.del.success": "已经从白名单移除",
"message.cmd.item_white.del.fail": "从白名单移除失败",
"message.cmd.entity_white.add.success": "已经添加到白名单",
"message.cmd.entity_white.add.fail": "添加到白名单失败",
"message.cmd.entity_white.del.success": "已经从白名单移除",
"message.cmd.entity_white.del.fail": "从白名单移除失败"
}

0 comments on commit 2b76ea2

Please sign in to comment.