Skip to content

Commit

Permalink
feat: Punishment
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Mar 11, 2024
1 parent cb7b28f commit 1f14b6a
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/AnvilListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -68,6 +69,7 @@ public void onAnvil(InventoryClickEvent event) {
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.ANVIL, originalItemName);
Punishment.punish(player);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/BookListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.impl.list.AdvancedList;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -113,6 +114,7 @@ public void onBook(PlayerEditBookEvent event) {
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.BOOK, outMessage);
Punishment.punish(player);
}

if (settingsManager.getProperty(PluginSettings.BOOK_SEND_MESSAGE) && shouldSendMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.TimingUtils;
Expand Down Expand Up @@ -58,6 +59,7 @@ public void onPlayerHeldItem(PlayerItemHeldEvent event) {
long endTime = System.currentTimeMillis();
TimingUtils.addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.ITEM, originalName);
Punishment.punish(player);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.PlayerUtils;
Expand Down Expand Up @@ -57,6 +58,7 @@ public void onLogin(PlayerLoginEvent event) {
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.NAME, playerName);
Punishment.punish(player);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/wdsj/asw/listener/SignListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.impl.list.AdvancedList;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -97,6 +98,7 @@ public void onSign(SignChangeEvent event) {
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.SIGN, outMessage);
Punishment.punish(player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -78,6 +79,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, originalMessage);
Punishment.punish(player);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.wdsj.asw.event.ASWFilterEvent;
import io.wdsj.asw.event.EventType;
import io.wdsj.asw.manage.notice.Notifier;
import io.wdsj.asw.manage.punish.Punishment;
import io.wdsj.asw.setting.PluginMessages;
import io.wdsj.asw.setting.PluginSettings;
import io.wdsj.asw.util.Utils;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent
long endTime = System.currentTimeMillis();
addProcessStatistic(endTime, startTime);
Notifier.notice(player, EventType.CHAT, message);
Punishment.punish(player);
return;
}

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/io/wdsj/asw/manage/punish/Punishment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.wdsj.asw.manage.punish;

import io.wdsj.asw.setting.PluginSettings;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Mob;
import org.bukkit.entity.Player;

import java.util.List;

import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager;

public class Punishment {
/**
* 对玩家执行配置中定义的惩罚。
* @param player 要惩罚的玩家
*/
public static void punish(Player player) {
List<String> punishList = settingsManager.getProperty(PluginSettings.PUNISHMENT);
for (String punish : punishList) {
String upperCasePunish = punish.toUpperCase();
if (upperCasePunish.startsWith("DAMAGE")) {
String[] damage = punish.split("\\|");
try {
double damageAmount = (damage.length == 2) ? Double.parseDouble(damage[1]) : 1.0D;
player.damage(damageAmount);
} catch (NumberFormatException e) {
player.damage(1.0D);
}
} else if (upperCasePunish.startsWith("HOSTILE")) {
String[] hostile = upperCasePunish.split("\\|");
try {
double radius = (hostile.length == 2) ? Double.parseDouble(hostile[1]) : 10D;
makeHostileTowardsPlayer(player, radius);
} catch (NumberFormatException e) {
makeHostileTowardsPlayer(player, 10D);
}
}
}
}

/**
* 使指定半径内的敌对生物对玩家表现出敌对行为。
* @param target 目标玩家
* @param radius 敌对生物的搜索半径
*/
private static void makeHostileTowardsPlayer(Player target, double radius) {
List<Entity> entities = target.getNearbyEntities(radius, radius, radius);
for (Entity entity : entities) {
if (entity instanceof Mob) {
Mob mob = (Mob) entity;
mob.setTarget(target);
}
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/io/wdsj/asw/setting/PluginSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class PluginSettings implements SettingsHolder {
@Comment({"玩家违规时是否提醒管理员(需权限advancedsensitivewords.notice)",
"Notify operators when player violated"})
public static final Property<Boolean> NOTICE_OPERATOR = newProperty("Plugin.noticeOperator", true);

@Comment({"玩家违规时的惩罚列表(留空为不进行惩罚)",
"Punishment after player swore"})
public static final Property<List<String>> PUNISHMENT = newListProperty("Plugin.punishment");
@Comment({"是否在插件启动时自动清除旧的日志文件",
"Whether to automatically clear old log files on plugin startup"})
public static final Property<Boolean> PURGE_LOG_FILE = newProperty("Plugin.purgeLogFile", false);
Expand Down

0 comments on commit 1f14b6a

Please sign in to comment.