Skip to content

Commit

Permalink
+ 配置结构优化,添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlimiter committed Dec 19, 2023
1 parent c3afdf2 commit 0cb1fba
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 80 deletions.
15 changes: 9 additions & 6 deletions src/main/java/nova/committee/atom/sweep/core/Sweeper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.projectile.*;
import net.minecraft.world.entity.vehicle.Boat;
import net.minecraft.world.item.Item;
import nova.committee.atom.sweep.Static;
import nova.committee.atom.sweep.core.model.ASItem;
import nova.committee.atom.sweep.core.model.ASMob;
import nova.committee.atom.sweep.init.config.ModConfig;
import nova.committee.atom.sweep.init.handler.SweepHandler;
Expand Down Expand Up @@ -92,22 +94,23 @@ public void sweep(MinecraftServer server) {
int killLivingCount = 0;
int killXpCount = 0;
int killOtherCount = 0;

Iterable<ServerLevel> worlds = server.getAllLevels();

for (ServerLevel world : worlds) {
if (ModConfig.INSTANCE.getItem().isItemEntityCleanupEnable()) {
killItemCount += cleanupItemEntity(world);
}
killItemCount += cleanupItemEntity(world);
}
if (ModConfig.INSTANCE.getMob().isMobEntityCleanupEnable()) {
if (ModConfig.INSTANCE.getMob().isAnimalEntitiesCleanupEnable())
killLivingCount += cleanupAnimalEntity(world);
if (ModConfig.INSTANCE.getMob().isMonsterEntitiesCleanupEnable())
killLivingCount += cleanupMonsterEntity(world);
}
}
if (ModConfig.INSTANCE.getOther().isExperienceOrbEntityCleanupEnable())
killXpCount += cleanupXpEntity(world);
killXpCount += cleanupXpEntity(world);

killOtherCount += cleanOtherEntities(world);
killOtherCount += cleanOtherEntities(world);


}
Expand All @@ -116,7 +119,7 @@ public void sweep(MinecraftServer server) {
}

public int cleanupItemEntity(ServerLevel world) {
return cleanupEntity(world, entity -> entity instanceof ItemEntity, entity -> true);
return cleanupEntity(world, entity -> entity instanceof ItemEntity, entity -> new ASItem((ItemEntity) entity).filtrate());
}

public int cleanupMonsterEntity(ServerLevel world) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ public ASItem(ItemEntity entity) {
* @return 白名单或者黑名单
*/
public boolean filtrate() {
if (ModConfig.INSTANCE.getItem().isItemEntitiesMatchMode()) {
if (ModConfig.INSTANCE.getItem().isItemWhiteMode()) {
// Whitelist
for (String s : ModConfig.INSTANCE.getItem().getItemEntitiesWhitelist()) {
if (itemMatch(s, this.registryName)) return false;
}
return true;
} else {
}

if (ModConfig.INSTANCE.getItem().isItemBlackMode()) {
// Blacklist
for (String s : ModConfig.INSTANCE.getItem().getItemEntitiesBlacklist()) {
if (itemMatch(s, this.registryName)) return true;
}
return false;
}

return true;
}

static boolean itemMatch(String s, ResourceLocation registryName) {
Expand Down
32 changes: 21 additions & 11 deletions src/main/java/nova/committee/atom/sweep/core/model/ASMob.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,36 @@ public ASMob(Mob entity) {

public boolean filtrate() {
int index;
if (ModConfig.INSTANCE.getMob().isMobEntityCleanupEnable()) {
if (ModConfig.INSTANCE.getMob().isMobWhiteMode()) {
// Whitelist
for (String s : ModConfig.INSTANCE.getMob().getMobEntitiesWhitelist()) {
if (s.equals(this.registryName.toString())) {
return false;
} else if ((index = s.indexOf('*')) != -1) {
s = s.substring(0, index - 1);
if (this.registryName.getNamespace().equals(s)) {
return false;
}
}
if (mobMatch(s, this.registryName)) return false;
}
return true;
} else {
}

if (ModConfig.INSTANCE.getMob().isMobBlackMode()) {
// Blacklist
for (String s : ModConfig.INSTANCE.getMob().getMobEntitiesBlacklist()) {
if (ASItem.itemMatch(s, this.registryName)) return true;
if (mobMatch(s, this.registryName)) return true;
}
return false;
}

return true;
}

static boolean mobMatch(String s, ResourceLocation registryName) {
int index;
if (s.equals(registryName.toString())) {
return true;
} else if ((index = s.indexOf('*')) != -1) {
s = s.substring(0, index - 1);
if (registryName.getNamespace().equals(s)) {
return false;
}
}
return false;
}

public Mob getEntity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import cn.evole.config.toml.AutoLoadTomlConfig;
import cn.evole.config.toml.annotation.TableField;
import cn.evole.libs.tomlj.TomlTable;
import com.google.gson.annotations.Expose;
import lombok.Getter;
import lombok.Setter;

/**
* Name: atomsweep / CommonConfig
Expand All @@ -15,16 +12,16 @@
*/

public class CommonConfig extends AutoLoadTomlConfig {
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "扫地周期(分钟)")
private int sweepPeriod = 4;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "提前通知时间(秒)")
private int sweepNotify = 20;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "倒计时时间(秒)")
private int sweepDiscount = 5;
@TableField(rightComment = "开启q群功能")
private String sweepNotice = "<演变> 注意:还有 %d 秒就要去你家吃饭了~";
@TableField(rightComment = "开启q群功能")
private String sweepNoticeComplete = "<演变> 这次一共吃掉了 %d 个掉落物, %d 个生物 %d 个经验球和 %d 个其他实体~";
@TableField(rightComment = "通知提示")
private String sweepNotice = "<演变> 注意:还有 {0} 秒就要去你家吃饭了~";
@TableField(rightComment = "清扫完通知提示")
private String sweepNoticeComplete = "<演变> 这次一共吃掉了 {0} 个掉落物, {1} 个生物 {2} 个经验球和 {3} 个其他实体~";

public CommonConfig() {
super(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
*/

public class ItemsConfig extends AutoLoadTomlConfig {
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "物品实体清理功能")
private boolean isItemEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
private boolean itemEntitiesMatchMode = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "白名单模式")
private boolean itemWhiteMode = true;
@TableField(rightComment = "黑名单模式")
private boolean itemBlackMode = true;
@TableField(rightComment = "白名单")
private List<String> itemEntitiesWhitelist = Arrays.asList("minecraft:diamond", "minecraft:emerald");
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "黑名单")
private List<String> itemEntitiesBlacklist = List.of();

public ItemsConfig() {
Expand All @@ -42,12 +44,20 @@ public void setItemEntityCleanupEnable(boolean itemEntityCleanupEnable) {
isItemEntityCleanupEnable = itemEntityCleanupEnable;
}

public boolean isItemEntitiesMatchMode() {
return itemEntitiesMatchMode;
public boolean isItemWhiteMode() {
return itemWhiteMode;
}

public void setItemEntitiesMatchMode(boolean itemEntitiesMatchMode) {
this.itemEntitiesMatchMode = itemEntitiesMatchMode;
public void setItemWhiteMode(boolean itemWhiteMode) {
this.itemWhiteMode = itemWhiteMode;
}

public boolean isItemBlackMode() {
return itemBlackMode;
}

public void setItemBlackMode(boolean itemBlackMode) {
this.itemBlackMode = itemBlackMode;
}

public List<String> getItemEntitiesWhitelist() {
Expand Down
34 changes: 22 additions & 12 deletions src/main/java/nova/committee/atom/sweep/init/config/MobsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
*/

public class MobsConfig extends AutoLoadTomlConfig {
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "生物实体清理功能(最高优先级)")
private boolean isMobEntityCleanupEnable = true;
@TableField(rightComment = "动物实体清理功能(次级)")
private boolean isAnimalEntitiesCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "怪物实体清理功能(次级)")
private boolean isMonsterEntitiesCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
private boolean isMobEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
private boolean mobEntitiesMatchMode = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "白名单模式")
private boolean mobWhiteMode = true;
@TableField(rightComment = "黑名单模式")
private boolean mobBlackMode = true;
@TableField(rightComment = "生物白名单")
private List<String> mobEntitiesWhitelist = Arrays.asList("minecraft:cat", "minecraft:mule", "minecraft:wolf", "minecraft:horse",
"minecraft:donkey", "minecraft:wither", "minecraft:guardian", "minecraft:villager", "minecraft:iron_golem", "minecraft:snow_golem",
"minecraft:vindicator", "minecraft:ender_dragon", "minecraft:elder_guardian");
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "生物黑名单")
private List<String> mobEntitiesBlacklist = List.of();

public boolean isAnimalEntitiesCleanupEnable() {
Expand All @@ -54,12 +56,20 @@ public void setMobEntityCleanupEnable(boolean mobEntityCleanupEnable) {
isMobEntityCleanupEnable = mobEntityCleanupEnable;
}

public boolean isMobEntitiesMatchMode() {
return mobEntitiesMatchMode;
public boolean isMobBlackMode() {
return mobBlackMode;
}

public void setMobBlackMode(boolean mobBlackMode) {
this.mobBlackMode = mobBlackMode;
}

public boolean isMobWhiteMode() {
return mobWhiteMode;
}

public void setMobEntitiesMatchMode(boolean mobEntitiesMatchMode) {
this.mobEntitiesMatchMode = mobEntitiesMatchMode;
public void setMobWhiteMode(boolean mobWhiteMode) {
this.mobWhiteMode = mobWhiteMode;
}

public List<String> getMobEntitiesWhitelist() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
*/

public class OthersConfig extends AutoLoadTomlConfig {
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "经验球实体清理功能")
private boolean isExperienceOrbEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "下落方块实体清理功能")
private boolean isFallingBlocksEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "箭头实体清理功能")
private boolean isArrowEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "三叉戟实体清理功能")
private boolean isTridentEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "投射物实体清理功能")
private boolean isDamagingProjectileEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "子弹实体清理功能")
private boolean isShulkerBulletEntityCleanupEnable = true;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "烟花火箭实体清理功能")
private boolean isFireworkRocketEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "物品框实体清理功能")
private boolean isItemFrameEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "画实体清理功能")
private boolean isPaintingEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "船实体清理功能")
private boolean isBoatEntityCleanupEnable = false;
@TableField(rightComment = "开启q群功能")
@TableField(rightComment = "TNT实体清理功能")
private boolean isTNTEntityCleanupEnable = true;

public boolean isExperienceOrbEntityCleanupEnable() {
Expand Down
17 changes: 8 additions & 9 deletions src/main/resources/assets/atomsweep/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"message.atomclean.cleanupItemCountdown": "Item entities will be removed in %d s!",
"message.atomclean.cleanupMobCountdown": "Mob entities will be removed in %d s!",
"message.atomclean.cleanupMonsterCountdown": "Monster entities will be removed in %d s!",
"message.atomclean.cleanupAnimalCountdown": "Animal entities will be removed in %d s!",

"message.atomclean.itemCleanupComplete": "%d item entity(entities) removed",
"message.atomclean.mobCleanupComplete": "%d mob entity(entities) removed",
"message.atomclean.monsterCleanupComplete": "%d monster entity(entities) removed",
"message.atomclean.animalCleanupComplete": "%d animal entity(entities) removed",
"message.atomclean.cleanupItemCountdown": "Item entities will be removed in {0} s!",
"message.atomclean.cleanupMobCountdown": "Mob entities will be removed in {0} s!",
"message.atomclean.cleanupMonsterCountdown": "Monster entities will be removed in {0} s!",
"message.atomclean.cleanupAnimalCountdown": "Animal entities will be removed in {0} s!",
"message.atomclean.itemCleanupComplete": "{0} item entity(entities) removed",
"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": "",
Expand Down
18 changes: 8 additions & 10 deletions src/main/resources/assets/atomsweep/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{

"message.atomclean.cleanupItemCountdown": "物品实体将在 %d 秒后被清理!",
"message.atomclean.cleanupMobCountdown": "生物实体将在 %d 秒后被清理!",
"message.atomclean.cleanupMonsterCountdown": "怪物实体将在 %d 秒后被清理!",
"message.atomclean.cleanupAnimalCountdown": "动物实体将在 %d 秒后被清理!",

"message.atomclean.itemCleanupComplete": "已清除 %d 个物品实体。",
"message.atomclean.mobCleanupComplete": "已清除 %d 个生物实体。",
"message.atomclean.monsterCleanupComplete": "已清除 %d 个怪物实体。",
"message.atomclean.animalCleanupComplete": "已清除 %d 个动物实体。",
"message.atomclean.cleanupItemCountdown": "物品实体将在 {0} 秒后被清理!",
"message.atomclean.cleanupMobCountdown": "生物实体将在 {0} 秒后被清理!",
"message.atomclean.cleanupMonsterCountdown": "怪物实体将在 {0} 秒后被清理!",
"message.atomclean.cleanupAnimalCountdown": "动物实体将在 {0} 秒后被清理!",
"message.atomclean.itemCleanupComplete": "已清除 {0} 个物品实体。",
"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": "已经从白名单移除",
Expand Down

0 comments on commit 0cb1fba

Please sign in to comment.