Skip to content

Commit 2c68685

Browse files
RhythmicRhythmic
authored andcommitted
start brig work, localehandler change
1 parent 38e2775 commit 2c68685

7 files changed

Lines changed: 221 additions & 290 deletions

File tree

pom.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<name>SimpleHomes</name>
1313

1414
<properties>
15-
<java.version>1.8</java.version>
15+
<java.version>21</java.version>
1616
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1717
</properties>
1818

@@ -61,17 +61,16 @@
6161
</repositories>
6262

6363
<dependencies>
64-
65-
<dependency>
66-
<groupId>org.xerial</groupId>
67-
<artifactId>sqlite-jdbc</artifactId>
68-
<version>3.45.1.0</version>
69-
</dependency>
7064
<dependency>
7165
<groupId>io.papermc.paper</groupId>
7266
<artifactId>paper-api</artifactId>
73-
<version>1.20.4-R0.1-SNAPSHOT</version>
67+
<version>1.21.5-R0.1-SNAPSHOT</version>
7468
<scope>provided</scope>
7569
</dependency>
70+
<dependency>
71+
<groupId>com.zaxxer</groupId>
72+
<artifactId>HikariCP</artifactId>
73+
<version>6.3.0</version>
74+
</dependency>
7675
</dependencies>
7776
</project>

src/main/java/simplexity/simplehomes/SimpleHomes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ private void handleConfig(){
5959
getConfig().options().copyDefaults(true);
6060
saveConfig();
6161
ConfigHandler.getInstance().loadConfigValues();
62-
LocaleHandler.getInstance().loadLocale();
62+
LocaleHandler.getInstance().reloadLocale();
6363
}
6464
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package simplexity.simplehomes.commands.brigstuff;
2+
3+
import com.mojang.brigadier.context.CommandContext;
4+
import io.papermc.paper.command.brigadier.CommandSourceStack;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
8+
import javax.annotation.Nullable;
9+
10+
@SuppressWarnings("UnstableApiUsage")
11+
public class CommandContextHelper {
12+
/**
13+
* Gets player sender from command context if one exists, null if none exists
14+
* @param ctx Command Context
15+
* @return Player
16+
*/
17+
@Nullable
18+
public static Player getPlayer(CommandContext<CommandSourceStack> ctx) {
19+
if (ctx.getSource().getSender() instanceof Player player) return player;
20+
return null;
21+
}
22+
23+
/**
24+
* Gets command sender from command context
25+
* @param ctx Command Context
26+
* @return CommandSender
27+
*/
28+
public static CommandSender getCommandSender(CommandContext<CommandSourceStack> ctx) {
29+
return ctx.getSource().getSender();
30+
}
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package simplexity.simplehomes.commands.brigstuff;
2+
3+
import com.mojang.brigadier.Message;
4+
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
5+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
6+
import io.papermc.paper.command.brigadier.MessageComponentSerializer;
7+
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
8+
import simplexity.simplehomes.SimpleHomes;
9+
import simplexity.simplehomes.configs.LocaleMessage;
10+
11+
public class Exceptions {
12+
13+
public static final SimpleCommandExceptionType MUST_BE_PLAYER = new SimpleCommandExceptionType(serialize(LocaleMessage.MUST_BE_PLAYER));
14+
public static final SimpleCommandExceptionType PROVIDE_HOME_NAME = new SimpleCommandExceptionType(serialize(LocaleMessage.PROVIDE_HOME_NAME));
15+
public static final SimpleCommandExceptionType HOME_ALREADY_EXISTS = new SimpleCommandExceptionType(serialize(LocaleMessage.HOME_ALREADY_EXISTS));
16+
public static final DynamicCommandExceptionType HOME_NOT_FOUND = new DynamicCommandExceptionType(name -> serialize(LocaleMessage.HOME_NOT_FOUND, name.toString()));
17+
public static final DynamicCommandExceptionType NULL_HOME = new DynamicCommandExceptionType(name -> serialize(LocaleMessage.NULL_HOME, name.toString()));
18+
public static final DynamicCommandExceptionType CANNOT_SET_MORE = new DynamicCommandExceptionType(count -> serialize(LocaleMessage.CANNOT_SET_MORE_HOMES, count.toString()));
19+
public static final DynamicCommandExceptionType CANNOT_USE_COMMAND = new DynamicCommandExceptionType(count -> serialize(LocaleMessage.CANNOT_USE_COMMAND, count.toString()));
20+
21+
22+
private static Message serialize(LocaleMessage localeMessage) {
23+
return MessageComponentSerializer.message().serialize(
24+
SimpleHomes.getMiniMessage().deserialize(
25+
localeMessage.getMessage()
26+
));
27+
}
28+
29+
private static Message serialize(LocaleMessage localeMessage, String value) {
30+
return MessageComponentSerializer.message().serialize(
31+
SimpleHomes.getMiniMessage().deserialize(
32+
localeMessage.getMessage(),
33+
Placeholder.parsed("value", value),
34+
Placeholder.parsed("name", value)
35+
));
36+
}
37+
38+
39+
40+
}

0 commit comments

Comments
 (0)