Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.vanishedd.spongetags;
- import com.vanishedd.spongetags.commands.CmdTag;
- import com.vanishedd.spongetags.database.Queries;
- import com.vanishedd.spongetags.listeners.PlayerActivity;
- import com.zaxxer.hikari.HikariDataSource;
- import org.spongepowered.api.Game;
- import org.spongepowered.api.Sponge;
- import org.spongepowered.api.command.args.GenericArguments;
- import org.spongepowered.api.command.spec.CommandSpec;
- import org.spongepowered.api.event.Listener;
- import org.spongepowered.api.event.game.state.GameStartedServerEvent;
- import org.spongepowered.api.event.game.state.GameStoppedServerEvent;
- import org.spongepowered.api.plugin.Plugin;
- import org.spongepowered.api.text.Text;
- import java.sql.Connection;
- import java.sql.SQLException;
- @Plugin(id="spongetags", name="Sponge Tag", version="1.0")
- public class SpongeTags {
- private static SpongeTags instance;
- public Game game;
- private HikariDataSource dataSource;
- public Connection connection;
- @Listener
- public void onServerStart(GameStartedServerEvent e) {
- instance = this;
- game = Sponge.getGame();
- dataSource = new HikariDataSource();
- dataSource.setJdbcUrl("jdbc:mysql://localhost/sakura");
- dataSource.setUsername("root");
- dataSource.setPassword("");
- dataSource.setDriverClassName("com.mysql.jdbc.Driver");
- registerCommands();
- registerListeners();
- registerMysql();
- }
- @Listener
- public void onServerStop(GameStoppedServerEvent e) {
- instance = null;
- }
- public static SpongeTags getInstance() {
- return instance;
- }
- private void registerCommands() {
- CommandSpec tagCommand = CommandSpec.builder()
- .description(Text.of("Manage player tags"))
- .arguments(
- GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("message")))
- )
- .executor(new CmdTag()).build();
- Sponge.getCommandManager().register(this, tagCommand, "titles", "title");
- }
- private void registerListeners() {
- Sponge.getEventManager().registerListeners(this, new PlayerActivity());
- }
- private void registerMysql() {
- try {
- connection = dataSource.getConnection();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- Queries.checkIfTableExists("tags", "playerUUID varchar(255), tag varchar(255), active tinyint(1), info varchar(255), uuid varchar(255), PRIMARY KEY (uuid)");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement