Skip to content
This repository was archived by the owner on May 8, 2021. It is now read-only.

Commit 7a301d2

Browse files
committed
Initial Commit
0 parents  commit 7a301d2

38 files changed

+2461
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.iml
2+
target
3+
.idea

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 David D'Amico and Glyart di Coletta Pierpaolo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

bungeecord/pom.xml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>aSQL-parent</artifactId>
7+
<groupId>com.glyart</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>aSQL-bungeecord</artifactId>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.8.1</version>
20+
<configuration>
21+
<source>11</source>
22+
<target>11</target>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-shade-plugin</artifactId>
28+
<version>3.2.4</version>
29+
<executions>
30+
<execution>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>shade</goal>
34+
</goals>
35+
<configuration>
36+
<createDependencyReducedPom>false</createDependencyReducedPom>
37+
</configuration>
38+
</execution>
39+
</executions>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
44+
<repositories>
45+
<repository>
46+
<id>bungeecord-repo</id>
47+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
48+
</repository>
49+
</repositories>
50+
51+
<dependencies>
52+
<dependency>
53+
<groupId>com.glyart</groupId>
54+
<artifactId>aSQL-common</artifactId>
55+
<version>${project.parent.version}</version>
56+
<scope>compile</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>net.md-5</groupId>
61+
<artifactId>bungeecord-api</artifactId>
62+
<version>1.16-R0.4-SNAPSHOT</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>com.intellij</groupId>
68+
<artifactId>annotations</artifactId>
69+
<version>12.0</version>
70+
<scope>compile</scope>
71+
</dependency>
72+
73+
<dependency>
74+
<groupId>org.projectlombok</groupId>
75+
<artifactId>lombok</artifactId>
76+
<version>1.18.16</version>
77+
<scope>provided</scope>
78+
</dependency>
79+
</dependencies>
80+
81+
</project>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.glyart.asql.bungeecord;
2+
3+
import com.glyart.asql.common.context.ContextScheduler;
4+
import lombok.AccessLevel;
5+
import lombok.NonNull;
6+
import lombok.RequiredArgsConstructor;
7+
import net.md_5.bungee.api.plugin.Plugin;
8+
9+
import java.util.concurrent.TimeUnit;
10+
11+
/**
12+
* Represents a task scheduling behavior through a Bungeecord Context.
13+
* There should be just one instance of ASQLBungeecordScheduler per Bungeecord Context.
14+
* @param <T> An existing Plugin
15+
*/
16+
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
17+
public final class ASQLBungeecordScheduler<T extends Plugin> implements ContextScheduler {
18+
19+
private final T plugin;
20+
21+
/**
22+
* Executes an asynchronous repeating task every given milliseconds, after the given milliseconds delay time.
23+
* @param runnable The task to run
24+
* @param delay the ticks to wait before running the task for the first time
25+
* @param period the ticks to wait before each run
26+
*/
27+
@Override
28+
public void async(@NonNull Runnable runnable, long delay, long period) {
29+
plugin.getProxy().getScheduler().schedule(plugin, runnable, delay, period, TimeUnit.MILLISECONDS);
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
@Override
36+
public void async(@NonNull Runnable runnable) {
37+
plugin.getProxy().getScheduler().runAsync(plugin, runnable);
38+
}
39+
40+
/**
41+
* Don't call this method. Sync context is unsupported on Bungeecord.
42+
* @throws UnsupportedOperationException if called because Bungeecord context doesn't support synchronous context
43+
*/
44+
@Override
45+
public void sync(@NonNull Runnable runnable, long delay, long period) {
46+
throw new UnsupportedOperationException("The Bungeecord context doesn't support this operation");
47+
}
48+
49+
/**
50+
* Don't call this method. Sync context is unsupported on Bungeecord.
51+
* @throws UnsupportedOperationException if called because Bungeecord context doesn't support synchronous context
52+
*/
53+
@Override
54+
public void sync(@NonNull Runnable runnable) {
55+
throw new UnsupportedOperationException("The Bungeecord context doesn't support this operation");
56+
}
57+
58+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
package com.glyart.asql.bungeecord;
2+
3+
import com.glyart.asql.common.context.ASQLContext;
4+
import com.glyart.asql.common.context.ContextScheduler;
5+
import com.glyart.asql.common.database.DataSourceCredentials;
6+
import com.glyart.asql.common.database.DataSourceHandler;
7+
import com.glyart.asql.common.database.DataTemplate;
8+
import com.glyart.asql.common.defaults.DefaultDataSourceHandler;
9+
import com.google.common.base.Preconditions;
10+
import net.md_5.bungee.api.plugin.Plugin;
11+
import org.jetbrains.annotations.NotNull;
12+
import org.jetbrains.annotations.Nullable;
13+
14+
import java.util.logging.Logger;
15+
16+
/**
17+
* Represents a modelled ASQLContext inside a Bungeecord Context. There can be multiple BungeecordASQLContext.
18+
* Creating different BungeecordASQLContext means that in the same Bungeecord Context you are willing
19+
* to interact with different data sources.
20+
*/
21+
public class BungeecordASQLContext implements ASQLContext<Plugin> {
22+
23+
private static ASQLBungeecordScheduler<? extends Plugin> asqlBungeecordScheduler;
24+
25+
private final Plugin plugin;
26+
private final DataSourceCredentials credentials;
27+
private final DataSourceHandler dataSourceHandler;
28+
private final DataTemplate<BungeecordASQLContext> dataTemplate;
29+
30+
protected BungeecordASQLContext(Plugin plugin, DataSourceCredentials credentials, DataSourceHandler dataSourceHandler) {
31+
this.plugin = plugin;
32+
this.credentials = credentials;
33+
this.dataSourceHandler = dataSourceHandler == null ? new DefaultDataSourceHandler(credentials, null) : dataSourceHandler;
34+
if (asqlBungeecordScheduler == null)
35+
asqlBungeecordScheduler = new ASQLBungeecordScheduler<>(plugin);
36+
37+
this.dataTemplate = new DataTemplate<>(this);
38+
}
39+
40+
@Override
41+
public ContextScheduler getScheduler() {
42+
return asqlBungeecordScheduler;
43+
}
44+
45+
@Override
46+
public DataTemplate<BungeecordASQLContext> getDataTemplate() {
47+
return dataTemplate;
48+
}
49+
50+
@Override
51+
public Plugin getPlugin() {
52+
return plugin;
53+
}
54+
55+
@Override
56+
public DataSourceHandler getDataSourceHandler() {
57+
return dataSourceHandler;
58+
}
59+
60+
@Override
61+
public Logger getLogger() {
62+
return plugin.getLogger();
63+
}
64+
65+
public static ContextBuilder builder() {
66+
return new ContextBuilder();
67+
}
68+
69+
public static class ContextBuilder {
70+
71+
private Plugin plugin;
72+
private DataSourceCredentials credentials;
73+
private DataSourceHandler dataSourceHandler;
74+
75+
private ContextBuilder() {
76+
77+
}
78+
79+
/**
80+
* Sets the Plugin which created this BungeecordASQLContext.
81+
* @param plugin the EXISTING Plugin which created this BungeecordASQLContext
82+
* @return This ContextBuilder instance
83+
*/
84+
public ContextBuilder setPlugin(@NotNull Plugin plugin) {
85+
Preconditions.checkNotNull(plugin, "Plugin cannot be null.");
86+
this.plugin = plugin;
87+
return this;
88+
}
89+
90+
/**
91+
* Sets the given credentials for connecting to a data source.
92+
* @param credentials The credentials for connecting to a data source
93+
* @return This ContextBuilder instance
94+
*/
95+
public ContextBuilder setCredentials(@NotNull DataSourceCredentials credentials) {
96+
Preconditions.checkNotNull(credentials, "DataSourceCredentials cannot be null.");
97+
this.credentials = credentials;
98+
return this;
99+
}
100+
101+
/**
102+
* Sets the handler for the data source interaction. If it's not provided then a Hikari based default implementation will be used.
103+
* @param dataSourceHandler The handler for the data source interaction.
104+
* @return This ContextBuilder instance
105+
* @see DefaultDataSourceHandler
106+
*/
107+
public ContextBuilder setDatabaseHandler(@Nullable DataSourceHandler dataSourceHandler) {
108+
this.dataSourceHandler = dataSourceHandler;
109+
return this;
110+
}
111+
112+
/**
113+
* Builds a new BungeecordASQLContext.
114+
* @return a new instance of BungeecordASQLContext
115+
*/
116+
@NotNull
117+
public BungeecordASQLContext build() {
118+
return new BungeecordASQLContext(plugin, credentials, dataSourceHandler);
119+
}
120+
}
121+
122+
}

common/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>aSQL-parent</artifactId>
7+
<groupId>com.glyart</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>aSQL-common</artifactId>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.apache.maven.plugins</groupId>
18+
<artifactId>maven-compiler-plugin</artifactId>
19+
<version>3.8.1</version>
20+
<configuration>
21+
<source>11</source>
22+
<target>11</target>
23+
</configuration>
24+
</plugin>
25+
<plugin>
26+
<groupId>org.apache.maven.plugins</groupId>
27+
<artifactId>maven-shade-plugin</artifactId>
28+
<version>3.2.4</version>
29+
<executions>
30+
<execution>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>shade</goal>
34+
</goals>
35+
<configuration>
36+
<createDependencyReducedPom>false</createDependencyReducedPom>
37+
</configuration>
38+
</execution>
39+
</executions>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
44+
<dependencies>
45+
<dependency>
46+
<groupId>com.zaxxer</groupId>
47+
<artifactId>HikariCP</artifactId>
48+
<version>3.4.5</version>
49+
<scope>compile</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>com.intellij</groupId>
54+
<artifactId>annotations</artifactId>
55+
<version>12.0</version>
56+
<scope>compile</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.projectlombok</groupId>
61+
<artifactId>lombok</artifactId>
62+
<version>1.18.16</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>com.google.guava</groupId>
68+
<artifactId>guava</artifactId>
69+
<version>23.0</version>
70+
<scope>compile</scope>
71+
</dependency>
72+
</dependencies>
73+
74+
</project>

0 commit comments

Comments
 (0)