Skip to content

Commit 3643ad1

Browse files
committed
Added files for DEV-2
1 parent 46f0f44 commit 3643ad1

29 files changed

Lines changed: 1371 additions & 163 deletions

.github/workflows/maven.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ name: Java CI with Maven
1010

1111
on:
1212
push:
13-
branches: [ "main", "dev" ]
1413
pull_request:
1514
branches: [ "main", "dev" ]
1615

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>tect.host</groupId>
88
<artifactId>TChat</artifactId>
9-
<version>5.0.0-DEV-1</version>
9+
<version>5.0.0-DEV-2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>TChat</name>
@@ -104,7 +104,7 @@
104104
<dependency>
105105
<groupId>io.papermc.paper</groupId>
106106
<artifactId>paper-api</artifactId>
107-
<version>26.1.2.build.53-stable</version>
107+
<version>26.1.2.build.61-stable</version>
108108
<scope>provided</scope>
109109
</dependency>
110110

src/main/java/tect/host/tpl/TChat.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import tect.host.tpl.config.MessagesManager;
99
import tect.host.tpl.listener.ChatListener;
1010
import tect.host.tpl.listener.PlayerJoinListener;
11-
import tect.host.tpl.manager.ChatProcessor;
12-
import tect.host.tpl.manager.JoinProcessor;
13-
import tect.host.tpl.manager.ModuleManager;
14-
import tect.host.tpl.manager.ModuleRegistry;
11+
import tect.host.tpl.manager.*;
1512
import tect.host.tpl.module.BukkitSchedulerAccess;
13+
import tect.host.tpl.module.ModuleCommand;
1614
import tect.host.tpl.module.ModuleContext;
1715
import tect.host.tpl.module.SchedulerAccess;
1816
import tect.host.tpl.module.hook.placeholderapi.PlaceholderApiHook;
1917

18+
import java.util.List;
19+
2020
public final class TChat extends JavaPlugin {
2121

2222
private ConfigManager configManager;
@@ -42,11 +42,8 @@ public void onEnable() {
4242

4343
placeholderApiHook.registerExpansion(this, moduleManager);
4444

45-
ChatProcessor chatProcessor = new ChatProcessor(moduleManager);
46-
getServer().getPluginManager().registerEvents(new ChatListener(chatProcessor), this);
47-
48-
JoinProcessor joinProcessor = new JoinProcessor(moduleManager);
49-
getServer().getPluginManager().registerEvents(new PlayerJoinListener(joinProcessor), this);
45+
getServer().getPluginManager().registerEvents(new ChatListener(new ChatProcessor(moduleManager)), this);
46+
getServer().getPluginManager().registerEvents(new PlayerJoinListener(new JoinProcessor(moduleManager)), this);
5047

5148
registerCommands();
5249
new Metrics(this, 23305);
@@ -66,10 +63,20 @@ public void reloadPluginState() {
6663

6764
private void registerCommands() {
6865
getLifecycleManager().registerEventHandler(LifecycleEvents.COMMANDS, event -> {
69-
TChatCommand cmd = new TChatCommand(this);
70-
71-
event.registrar().register("tchat", cmd);
72-
event.registrar().register("chat", cmd);
66+
TChatCommand tChatCommand = new TChatCommand(this);
67+
event.registrar().register("tchat", tChatCommand);
68+
event.registrar().register("chat", tChatCommand);
69+
70+
for (ModuleDescriptor descriptor : ModuleRegistry.createDefaultRegistry()) {
71+
var cmdFactory = descriptor.getCommandFactory();
72+
if (cmdFactory != null) {
73+
ModuleCommand cmd = cmdFactory.apply(moduleManager);
74+
event.registrar().register(cmd.getName(), cmd);
75+
for (String alias : cmd.getAliases()) {
76+
event.registrar().register(alias, cmd);
77+
}
78+
}
79+
}
7380
});
7481
}
7582

src/main/java/tect/host/tpl/config/migration/ConfigMigrations.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ public final class ConfigMigrations {
99
private ConfigMigrations() {}
1010

1111
public static @NonNull ConfigMigrator forConfig(@NonNull Logger logger) {
12-
return new ConfigMigrator(logger, "config.yml");
12+
return new ConfigMigrator(logger, "config.yml")
1313

1414
// v0 -> v1
15-
//.addMigration(config -> {
16-
// new options here
17-
// if (!config.isSet("modules.announcements")) {
18-
// config.set("modules.announcements", false);
19-
// }
20-
//});
15+
.addMigrations(config -> {
16+
if (!config.isSet("modules.blocked-words")) {
17+
config.set("modules.blocked-words", false);
18+
}
19+
});
2120
}
2221
}

src/main/java/tect/host/tpl/config/migration/ConfigMigrator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.io.File;
77
import java.io.IOException;
88
import java.util.ArrayList;
9+
import java.util.Collections;
910
import java.util.List;
1011
import java.util.logging.Level;
1112
import java.util.logging.Logger;
@@ -27,8 +28,6 @@ public ConfigMigrator(@NonNull Logger logger, @NonNull String fileName) {
2728
/**
2829
* Applies all pending migrations to the given FileConfiguration
2930
* If any changes are made, the file will be saved to disk
30-
*
31-
* @return true if at least one migration was applied
3231
*/
3332
public boolean migrate(@NonNull FileConfiguration config, @NonNull File file) {
3433
int current = config.getInt(VERSION_KEY, 0);
@@ -57,4 +56,14 @@ public boolean migrate(@NonNull FileConfiguration config, @NonNull File file) {
5756

5857
return true;
5958
}
59+
60+
public @NonNull ConfigMigrator addMigration(@NonNull ConfigMigration migration) {
61+
migrations.add(migration);
62+
return this;
63+
}
64+
65+
public @NonNull ConfigMigrator addMigrations(@NonNull ConfigMigration... steps) {
66+
Collections.addAll(migrations, steps);
67+
return this;
68+
}
6069
}

src/main/java/tect/host/tpl/config/migration/LangMigrations.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,41 @@ private LangMigrations() {}
1111

1212
@Contract("_, _ -> new")
1313
public static @NonNull ConfigMigrator create(@NonNull Logger logger, String langFileName) {
14-
return new ConfigMigrator(logger, langFileName);
14+
return new ConfigMigrator(logger, langFileName)
1515

1616
// v0 -> v1
17-
//.addMigration(config -> {
18-
// if (!config.isSet("path.path")) {
19-
// config.set("path.path", "message");
20-
// }
21-
//});
17+
.addMigration(config -> {
18+
if (!config.isSet("blocked-words-module-disabled")) {
19+
config.set("blocked-words-module-disabled", "<red>The blocked-words module is not enabled.</red>");
20+
}
21+
22+
if (!config.isSet("blocked-words-usage")) {
23+
config.set("blocked-words-usage", "<gray>Usage: /blockedwords <add|remove|list> [word]</gray>");
24+
}
25+
26+
if (!config.isSet("blocked-words-add-success")) {
27+
config.set("blocked-words-add-success", "<green>Word added: <white>%word%</white></green>");
28+
}
29+
30+
if (!config.isSet("blocked-words-add-duplicate")) {
31+
config.set("blocked-words-add-duplicate", "<yellow>That word is already blocked.</yellow>");
32+
}
33+
34+
if (!config.isSet("blocked-words-remove-success")) {
35+
config.set("blocked-words-remove-success", "<green>Word removed: <white>%word%</white></green>");
36+
}
37+
38+
if (!config.isSet("blocked-words-remove-not-found")) {
39+
config.set("blocked-words-remove-not-found", "<yellow>That word is not in the list.</yellow>");
40+
}
41+
42+
if (!config.isSet("blocked-words-list-empty")) {
43+
config.set("blocked-words-list-empty", "<gray>No words are currently blocked.</gray>");
44+
}
45+
46+
if (!config.isSet("blocked-words-list")) {
47+
config.set("blocked-words-list", "<gold>Blocked words (%count%): <white>%words%</white></gold>");
48+
}
49+
});
2250
}
2351
}

src/main/java/tect/host/tpl/listener/ChatListener.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ public void onChat(@NonNull AsyncChatEvent event) {
3131

3232
if (ctx.isCancelled()) { event.setCancelled(true); return; }
3333

34-
if (ctx.getFormat() != null) {
35-
event.renderer((source, dn, msg, viewer) -> ctx.getFormat());
34+
Component format = ctx.getFormat();
35+
if (format != null) {
36+
event.renderer((source, dn, msg, viewer) -> format);
37+
} else if (ctx.hasRawOverride()) {
38+
event.message(Component.text(ctx.getEffectiveRaw()));
3639
} else if (!ctx.getMessage().equals(original)) {
3740
event.message(ctx.getMessage());
3841
}
39-
40-
// If no module sets the format, Paper uses its default renderer
41-
// This is the expected behavior when all formatting modules are disabled
4242
}
4343
}

src/main/java/tect/host/tpl/manager/ChatProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
import tect.host.tpl.module.ModulePhase;
66
import tect.host.tpl.util.MessageContext;
77

8+
import java.util.EnumSet;
89
import java.util.List;
910

1011
public final class ChatProcessor {
1112

12-
private static final List<ModulePhase> PHASES = List.of(ModulePhase.values());
13+
private static final EnumSet<ModulePhase> PHASES = EnumSet.allOf(ModulePhase.class);
14+
1315
private final ModuleManager moduleManager;
1416

1517
public ChatProcessor(ModuleManager moduleManager) {

src/main/java/tect/host/tpl/manager/ModuleDescriptor.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import org.jetbrains.annotations.Contract;
44
import org.jspecify.annotations.NonNull;
55
import org.jspecify.annotations.Nullable;
6+
import tect.host.tpl.module.ModuleCommand;
7+
import tect.host.tpl.module.ModuleContext;
68
import tect.host.tpl.module.ModulePhase;
79

810
import java.util.Set;
11+
import java.util.function.BiFunction;
12+
import java.util.function.Function;
913

1014
public final class ModuleDescriptor {
1115

@@ -15,6 +19,7 @@ public final class ModuleDescriptor {
1519
private final Set<String> requiredModules;
1620
private final @Nullable ModulePhase phase;
1721
private final int priority;
22+
private final @Nullable Function<ModuleManager, ModuleCommand> commandFactory;
1823

1924
private ModuleDescriptor(@NonNull Builder builder) {
2025
this.id = builder.id;
@@ -23,6 +28,7 @@ private ModuleDescriptor(@NonNull Builder builder) {
2328
this.requiredModules = Set.copyOf(builder.requiredModules);
2429
this.phase = builder.phase;
2530
this.priority = builder.priority;
31+
this.commandFactory = builder.commandFactory;
2632
}
2733

2834
@Contract("_, _, _ -> new")
@@ -37,6 +43,10 @@ private ModuleDescriptor(@NonNull Builder builder) {
3743
public @Nullable ModulePhase getPhase() { return phase; }
3844
public int getPriority() { return priority; }
3945

46+
public @Nullable Function<ModuleManager, ModuleCommand> getCommandFactory() {
47+
return commandFactory;
48+
}
49+
4050
public static final class Builder {
4151

4252
private final String id;
@@ -45,17 +55,14 @@ public static final class Builder {
4555
private Set<String> requiredModules = Set.of();
4656
private @Nullable ModulePhase phase = null;
4757
private int priority = 100;
58+
private @Nullable Function<ModuleManager, ModuleCommand> commandFactory = null;
4859

4960
private Builder(String id, String togglePath, ModuleFactory factory) {
5061
this.id = id;
5162
this.togglePath = togglePath;
5263
this.factory = factory;
5364
}
5465

55-
/**
56-
* Each call to requires() replaces the previous set entirely
57-
* To declare multiple dependencies, pass all IDs in one call: .requires("a", "b")
58-
*/
5966
public Builder requires(@NonNull String... moduleIds) {
6067
this.requiredModules = Set.of(moduleIds);
6168
return this;
@@ -71,6 +78,11 @@ public Builder priority(int priority) {
7178
return this;
7279
}
7380

81+
public Builder command(@NonNull Function<ModuleManager, ModuleCommand> commandFactory) {
82+
this.commandFactory = commandFactory;
83+
return this;
84+
}
85+
7486
@Contract(" -> new")
7587
public @NonNull ModuleDescriptor build() {
7688
return new ModuleDescriptor(this);

0 commit comments

Comments
 (0)