-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(database): Dropped MineSQL with original easysql registry
- Loading branch information
Showing
10 changed files
with
200 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package com.artformgames.core; | ||
|
||
import cc.carm.lib.easysql.api.SQLManager; | ||
import com.artformgames.core.user.manager.UserManager; | ||
import io.github.leonardosnt.bungeechannelapi.BungeeChannelApi; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
interface ArtCorePlugin { | ||
|
||
@NotNull UserManager<?> getUserManager(); | ||
@NotNull SQLManager getSQLManager(); | ||
|
||
@NotNull UserManager<?> getUserManager(); | ||
|
||
@NotNull BungeeChannelApi getBungeeAPI(); | ||
|
||
|
||
} |
47 changes: 47 additions & 0 deletions
47
api/src/main/java/com/artformgames/core/conf/MessagesRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.artformgames.core.conf; | ||
|
||
import cc.carm.lib.configuration.core.ConfigurationRoot; | ||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageListBuilder; | ||
import cc.carm.lib.mineconfiguration.bukkit.builder.message.CraftMessageValueBuilder; | ||
import cc.carm.lib.mineconfiguration.bukkit.builder.title.TitleConfigBuilder; | ||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessage; | ||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList; | ||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredTitle; | ||
import de.themoep.minedown.MineDown; | ||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import net.md_5.bungee.api.chat.BaseComponent; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
public abstract class MessagesRoot extends ConfigurationRoot { | ||
|
||
protected static @NotNull CraftMessageListBuilder<BaseComponent[]> list() { | ||
return ConfiguredMessageList.create(getParser()) | ||
.whenSend((sender, message) -> message.forEach(m -> sender.spigot().sendMessage(m))); | ||
} | ||
|
||
protected static @NotNull CraftMessageValueBuilder<BaseComponent[]> value() { | ||
return ConfiguredMessage.create(getParser()) | ||
.whenSend((sender, message) -> sender.spigot().sendMessage(message)); | ||
} | ||
|
||
protected static @NotNull TitleConfigBuilder title() { | ||
return ConfiguredTitle.create(); | ||
} | ||
|
||
private static @NotNull BiFunction<CommandSender, String, BaseComponent[]> getParser() { | ||
return (sender, message) -> { | ||
if (sender == null) return MineDown.parse(message); | ||
if (sender instanceof Player player) { | ||
return MineDown.parse(PlaceholderAPI.setPlaceholders(player, message)); | ||
} else { | ||
return MineDown.parse(message); | ||
} | ||
}; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
plugin/src/main/java/com/artformgames/core/data/DBConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.artformgames.core.data; | ||
|
||
import cc.carm.lib.configuration.core.ConfigurationRoot; | ||
import cc.carm.lib.configuration.core.annotation.ConfigPath; | ||
import cc.carm.lib.configuration.core.annotation.HeaderComment; | ||
import cc.carm.lib.configuration.core.value.ConfigValue; | ||
import cc.carm.lib.configuration.core.value.type.ConfiguredValue; | ||
|
||
public class DBConfiguration extends ConfigurationRoot { | ||
|
||
@ConfigPath("driver") | ||
@HeaderComment({ | ||
"数据库驱动配置,请根据数据库类型设置。", | ||
"默认为MySQL: com.mysql.cj.jdbc.Driver", | ||
}) | ||
protected static final ConfigValue<String> DRIVER_NAME = ConfiguredValue.of( | ||
String.class, "com.mysql.cj.jdbc.Driver" | ||
); | ||
|
||
protected static final ConfigValue<String> HOST = ConfiguredValue.of(String.class, "127.0.0.1"); | ||
protected static final ConfigValue<Integer> PORT = ConfiguredValue.of(Integer.class, 3306); | ||
protected static final ConfigValue<String> DATABASE = ConfiguredValue.of(String.class, "minecraft"); | ||
protected static final ConfigValue<String> USERNAME = ConfiguredValue.of(String.class, "root"); | ||
protected static final ConfigValue<String> PASSWORD = ConfiguredValue.of(String.class, "password"); | ||
protected static final ConfigValue<String> EXTRA = ConfiguredValue.of(String.class, "?useSSL=false"); | ||
|
||
protected static String buildJDBC() { | ||
return String.format("jdbc:mysql://%s:%s/%s%s", | ||
HOST.getNotNull(), PORT.getNotNull(), DATABASE.getNotNull(), EXTRA.getNotNull() | ||
); | ||
} | ||
|
||
|
||
} |
54 changes: 54 additions & 0 deletions
54
plugin/src/main/java/com/artformgames/core/data/DataManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.artformgames.core.data; | ||
|
||
import cc.carm.lib.easysql.EasySQL; | ||
import cc.carm.lib.easysql.api.SQLManager; | ||
import com.artformgames.core.Main; | ||
|
||
import java.util.logging.Logger; | ||
|
||
|
||
public class DataManager { | ||
|
||
|
||
private final Logger logger; | ||
private SQLManager sqlManager; | ||
|
||
public DataManager(Logger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
public Logger getLogger() { | ||
return logger; | ||
} | ||
|
||
public boolean initialize() { | ||
try { | ||
getLogger().info(" Connecting to database..."); | ||
this.sqlManager = EasySQL.createManager( | ||
DBConfiguration.DRIVER_NAME.getNotNull(), DBConfiguration.buildJDBC(), | ||
DBConfiguration.USERNAME.getNotNull(), DBConfiguration.PASSWORD.getNotNull() | ||
); | ||
this.sqlManager.setDebugMode(() -> Main.getInstance().isDebugging()); | ||
} catch (Exception exception) { | ||
getLogger().severe("Error connecting to database, please check the configuration."); | ||
exception.printStackTrace(); | ||
return false; | ||
} | ||
|
||
getLogger().info(" Initializing tables..."); | ||
DataTables.initializeTables(this.sqlManager); | ||
|
||
return true; | ||
} | ||
|
||
public void shutdown() { | ||
EasySQL.shutdownManager(getSQLManager()); | ||
this.sqlManager = null; | ||
} | ||
|
||
public SQLManager getSQLManager() { | ||
return sqlManager; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.