Skip to content

Commit 9dd3f30

Browse files
committed
Rename methods
1 parent 7a4cf97 commit 9dd3f30

File tree

7 files changed

+69
-79
lines changed

7 files changed

+69
-79
lines changed

bukkit/src/main/java/io/wdsj/asw/bukkit/manage/punish/Punishment.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public static void processSinglePunish(Player player, String method) throws Ille
4242
case DAMAGE:
4343
try {
4444
double damageAmount = (normalPunish.length >= 2) ? Double.parseDouble(normalPunish[1]) : 1.0D;
45-
SchedulingUtils.runSyncIfFolia(player, () -> player.damage(damageAmount));
45+
SchedulingUtils.runSyncAtEntityIfFolia(player, () -> player.damage(damageAmount));
4646
} catch (NumberFormatException e) {
47-
SchedulingUtils.runSyncIfFolia(player, () -> player.damage(1.0D));
47+
SchedulingUtils.runSyncAtEntityIfFolia(player, () -> player.damage(1.0D));
4848
}
4949
break;
5050
case HOSTILE:
@@ -77,17 +77,17 @@ public static void processSinglePunish(Player player, String method) throws Ille
7777
if (potionEffect == null) throw new IllegalArgumentException("Unknown potion effect");
7878
switch (normalPunish.length) {
7979
case 2:
80-
SchedulingUtils.runSyncIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, 10, 0)));
80+
SchedulingUtils.runSyncAtEntityIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, 10, 0)));
8181
break;
8282
case 3:
8383
int duration_3 = Integer.parseInt(normalPunish[2]);
84-
SchedulingUtils.runSyncIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, duration_3 * 20, 0)));
84+
SchedulingUtils.runSyncAtEntityIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, duration_3 * 20, 0)));
8585
break;
8686
case 4:
8787
default:
8888
int duration_4 = Integer.parseInt(normalPunish[2]);
8989
int amplifier = Integer.parseInt(normalPunish[3]);
90-
SchedulingUtils.runSyncIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, duration_4 * 20, amplifier)));
90+
SchedulingUtils.runSyncAtEntityIfFolia(player, () -> player.addPotionEffect(new PotionEffect(potionEffect, duration_4 * 20, amplifier)));
9191
break;
9292
}
9393
break;
@@ -111,10 +111,10 @@ public static void processSinglePunish(Player player, String method) throws Ille
111111
* @param radius 敌对生物的搜索半径
112112
*/
113113
private static void makeHostileTowardsPlayer(Player target, double radius) {
114-
SchedulingUtils.runSyncIfFolia(target, () -> {
114+
SchedulingUtils.runSyncAtEntityIfFolia(target, () -> {
115115
List<Entity> entities = target.getNearbyEntities(radius, radius, radius);
116116
for (Entity entity : entities) {
117-
SchedulingUtils.runSyncIfFolia(entity, () -> {
117+
SchedulingUtils.runSyncAtEntityIfFolia(entity, () -> {
118118
if (entity instanceof Mob && !entity.hasMetadata("NPC")) {
119119
Mob mob = (Mob) entity;
120120
mob.setTarget(target);

bukkit/src/main/java/io/wdsj/asw/bukkit/type/TimedString.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

bukkit/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public static void runSyncIfFolia(Runnable runnable) {
1919
}
2020
}
2121

22-
public static void runSyncIfFolia(Entity entity, Runnable runnable) {
22+
public static void runSyncAtEntityIfFolia(Entity entity, Runnable runnable) {
2323
if (isFolia) {
2424
AdvancedSensitiveWords.getScheduler().runTask(entity, runnable);
2525
} else {
2626
runnable.run();
2727
}
2828
}
2929

30-
public static void runSyncIfFolia(Location location, Runnable runnable) {
30+
public static void runSyncAtLocationIfFolia(Location location, Runnable runnable) {
3131
if (isFolia) {
3232
AdvancedSensitiveWords.getScheduler().runTask(location, runnable);
3333
} else {

bukkit/src/main/java/io/wdsj/asw/bukkit/util/context/ChatContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.wdsj.asw.bukkit.util.context;
22

33
import io.wdsj.asw.bukkit.setting.PluginSettings;
4-
import io.wdsj.asw.bukkit.type.TimedString;
4+
import io.wdsj.asw.common.datatype.TimedString;
55
import org.bukkit.entity.Player;
66

77
import java.util.ArrayDeque;
@@ -22,14 +22,14 @@ public static void addMessage(Player player, String message) {
2222
history.pollFirst();
2323
}
2424
if (message.trim().isEmpty()) return;
25-
history.offerLast(new TimedString(message.trim(), System.currentTimeMillis()));
25+
history.offerLast(TimedString.of(message.trim()));
2626
}
2727

2828
public static Deque<String> getHistory(Player player) {
2929
Deque<TimedString> tsHistory = chatHistory.getOrDefault(player, new ArrayDeque<>());
3030
return tsHistory.stream()
3131
.filter(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 < settingsManager.getProperty(PluginSettings.CHAT_CONTEXT_TIME_LIMIT))
32-
.map(TimedString::getMessage)
32+
.map(TimedString::getString)
3333
.collect(ArrayDeque::new, ArrayDeque::add, ArrayDeque::addAll);
3434
}
3535

bukkit/src/main/java/io/wdsj/asw/bukkit/util/context/SignContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.wdsj.asw.bukkit.util.context;
22

33
import io.wdsj.asw.bukkit.setting.PluginSettings;
4-
import io.wdsj.asw.bukkit.type.TimedString;
4+
import io.wdsj.asw.common.datatype.TimedString;
55
import org.bukkit.entity.Player;
66

77
import java.util.ArrayDeque;
@@ -22,14 +22,14 @@ public static void addMessage(Player player, String message) {
2222
history.pollFirst();
2323
}
2424
if (message.trim().isEmpty()) return;
25-
history.offerLast(new TimedString(message.trim(), System.currentTimeMillis()));
25+
history.offerLast(TimedString.of(message.trim()));
2626
}
2727

2828
public static Deque<String> getHistory(Player player) {
2929
Deque<TimedString> tsHistory = signEditHistory.getOrDefault(player, new ArrayDeque<>());
3030
return tsHistory.stream()
3131
.filter(timedString -> (System.currentTimeMillis() - timedString.getTime()) / 1000 < settingsManager.getProperty(PluginSettings.SIGN_CONTEXT_TIME_LIMIT))
32-
.map(TimedString::getMessage)
32+
.map(TimedString::getString)
3333
.collect(ArrayDeque::new, ArrayDeque::add, ArrayDeque::addAll);
3434
}
3535

bukkit/src/main/resources/sensitive_word_dict.txt

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10714,15 +10714,9 @@ x逼
1071410714
佛同修
1071510715
佛展千手法
1071610716
佛怀煽仇录
10717-
佛教
10718-
佛教音乐下载
10719-
佛祖
1072010717
作ai
1072110718
作ོ嗳ོv
1072210719
作各种证
10723-
作弊
10724-
作弊器
10725-
作弊工具
1072610720
作弊接收器
1072710721
作弊接收设备
1072810722
作弊设备供应qq
@@ -46050,16 +46044,6 @@ jianzheng
4605046044
美咲留衣无码
4605146045
美咲留衣种子
4605246046
美咲麻衣种子
46053-
美国
46054-
美国3箭气枪出货
46055-
美国c2007
46056-
美国之音
46057-
美国乐透游戏
46058-
美国佬
46059-
美国军刀出售
46060-
美国凯德
46061-
美国原装
46062-
美国参考
4606346047
美国处女
4606446048
美国大使代替网络上的网友问
4606546049
美国小姐淫荡舔乳照
@@ -52638,31 +52622,9 @@ jianzheng
5263852622
铅弹鸟枪直销
5263952623
铅弹鸟枪购买
5264052624
铅弹鸟枪销售
52641-
铊出售qq
52642-
铊盐
52643-
铊盐供应
52644-
铊盐供应qq
52645-
铊盐出售
52646-
铊盐出售qq
52647-
铊盐提供
52648-
铊盐销售qq
52649-
铊粉供应
52650-
铊粉提供
52651-
铝热
52652-
铝热剂
52653-
铝热剂燃烧弹
5265452625
铬酸
5265552626
铭记印尼
5265652627
铲除负面信息
52657-
铵木
52658-
铵梯炸药出售
52659-
铵梯类炸药出售
52660-
铵油炸药出售
52661-
铵煤
52662-
铵磺
52663-
铵胍
52664-
铵萘
52665-
铵邻
5266652628
银剑天使
5266752629
银屑胶囊
5266852630
银川qq群
@@ -55337,9 +55299,6 @@ jianzheng
5533755299
颠覆国家政权
5533855300
风中飞舞的血滴
5533955301
风吹亚纪种子
55340-
风吹凉
55341-
风吹凉种子
55342-
风姿物语
5534355302
风尘劫
5534455303
风尘劫txt
5534555304
风尘劫txt全集
@@ -56379,7 +56338,6 @@ jianzheng
5637956338
魔幻森林
5638056339
魔性的meinv铃木麻奈美
5638156340
魔性的美女铃木麻奈美
56382-
魔教
5638356341
魔法奇兵
5638456342
魔法飞球
5638556343
魔王神官和勇者美少女
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.wdsj.asw.common.datatype;
2+
3+
import java.util.Objects;
4+
5+
/**
6+
* A class that represents a string with timestamp.
7+
* <p>
8+
* Represents a string paired with a timestamp, typically used to track
9+
* when the string was generated or modified.
10+
* <p>
11+
* Example usage:
12+
* <pre>
13+
* TimedString timedString = TimedString.of("Hello World", System.currentTimeMillis());
14+
* </pre>
15+
*
16+
* This class is immutable and thread-safe.
17+
*
18+
* @author HaHaWTH
19+
*/
20+
public class TimedString {
21+
private final String str;
22+
private final long time;
23+
24+
private TimedString(String str, long time) {
25+
this.str = str;
26+
this.time = time;
27+
}
28+
29+
public String getString() {
30+
return str;
31+
}
32+
33+
public long getTime() {
34+
return time;
35+
}
36+
37+
public static TimedString of(String str, long time) {
38+
Objects.requireNonNull(str, "String cannot be null");
39+
if (time < 0) throw new IllegalArgumentException("Time cannot be negative");
40+
return new TimedString(str, time);
41+
}
42+
43+
public static TimedString of(String str) {
44+
return of(str, System.currentTimeMillis());
45+
}
46+
47+
@Override
48+
public String toString() {
49+
return "TimedString{" +
50+
"str='" + str + '\'' +
51+
", time=" + time +
52+
'}';
53+
}
54+
}

0 commit comments

Comments
 (0)