-
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.
3.0.1-beta - add mySQL support to save current notify state, add mult…
…iproxy support
- Loading branch information
Showing
16 changed files
with
295 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-api:1.15-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.15-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" /> | ||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-config:1.15-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.25" level="project" /> | ||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-event:1.15-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: net.md-5:bungeecord-protocol:1.15-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: net.md-5:brigadier:1.0.16-SNAPSHOT" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.44.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: net.sf.trove4j:core:3.1.0" level="project" /> | ||
<orderEntry type="library" name="Maven: com.google.guava:guava:20.0" level="project" /> | ||
<orderEntry type="module-library"> | ||
<library name="Maven: cloud.timo.TimoCloud:TimoCloud-API:6.0.0"> | ||
<CLASSES> | ||
<root url="jar://$MODULE_DIR$/libs/TimoCloud.jar!/" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES /> | ||
</library> | ||
</orderEntry> | ||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.6" level="project" /> | ||
</component> | ||
</module> |
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
src/main/java/cloud/timo/CloudNotify/commands/CloudNotifyCommand.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 cloud.timo.CloudNotify.commands; | ||
|
||
import cloud.timo.CloudNotify.CloudNotify; | ||
import cloud.timo.CloudNotify.managers.MessageManager; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.plugin.Command; | ||
|
||
public class CloudNotifyCommand extends Command { | ||
|
||
public CloudNotifyCommand(String name, String permissions) { | ||
super(name, permissions); | ||
ProxyServer.getInstance().getPluginManager().registerCommand(CloudNotify.getInstance(), this); | ||
} | ||
|
||
@Override | ||
public void execute(CommandSender commandSender, String[] args) { | ||
if (!(commandSender instanceof ProxiedPlayer)) { | ||
MessageManager.sendMessage(commandSender, CloudNotify.getInstance().getFileManager().getMessages().getString("onlyPlayer")); | ||
return; | ||
} | ||
ProxiedPlayer proxiedPlayer = (ProxiedPlayer) commandSender; | ||
|
||
if (args.length == 0) { | ||
boolean currentState = CloudNotify.getInstance().getDatabaseManager().getNotifyState(proxiedPlayer.getUniqueId()); | ||
currentState = !currentState; | ||
|
||
CloudNotify.getInstance().getDatabaseManager().setNotifyState(proxiedPlayer.getUniqueId(), currentState); | ||
MessageManager.sendMessage(commandSender, CloudNotify.getInstance().getFileManager().getMessages().getString("changeStateCommand").replace("{0}", (currentState) ? CloudNotify.getInstance().getFileManager().getMessages().getString("enabled") :CloudNotify.getInstance().getFileManager().getMessages().getString("disabled"))); | ||
} | ||
} | ||
|
||
} |
9 changes: 4 additions & 5 deletions
9
src/main/java/cloud/timo/CloudNotify/listeners/ServerRegisterListener.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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
package cloud.timo.CloudNotify.listeners; | ||
|
||
import cloud.timo.CloudNotify.utils.NotifyType; | ||
import cloud.timo.CloudNotify.CloudNotify; | ||
import cloud.timo.TimoCloud.api.TimoCloudAPI; | ||
import cloud.timo.TimoCloud.api.events.EventHandler; | ||
import cloud.timo.TimoCloud.api.events.Listener; | ||
import cloud.timo.CloudNotify.CloudNotify; | ||
import cloud.timo.TimoCloud.api.events.server.ServerRegisterEvent; | ||
|
||
public class ServerRegisterListener implements Listener { | ||
|
||
public ServerRegisterListener(){ | ||
TimoCloudAPI.getEventImplementation().registerListener(this); | ||
public ServerRegisterListener() { | ||
TimoCloudAPI.getEventAPI().registerListener(this); | ||
} | ||
|
||
@EventHandler | ||
public void onServerRegister(ServerRegisterEvent event) { | ||
CloudNotify.getInstance().getHelper().notify(NotifyType.REGISTER, event.getServer()); | ||
CloudNotify.getInstance().getHelper().initiatingNotification(event, event.getServer()); | ||
} | ||
|
||
} |
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
77 changes: 77 additions & 0 deletions
77
src/main/java/cloud/timo/CloudNotify/managers/DatabaseManager.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,77 @@ | ||
package cloud.timo.CloudNotify.managers; | ||
|
||
import cloud.timo.CloudNotify.CloudNotify; | ||
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.Statement; | ||
import java.util.UUID; | ||
|
||
public class DatabaseManager extends Thread { | ||
public MysqlDataSource dataSource; | ||
|
||
public DatabaseManager() { | ||
start(); | ||
dataSource = new MysqlDataSource(); | ||
dataSource.setUseSSL(CloudNotify.getInstance().getFileManager().getConfig().getBoolean("MySQL.useSSL")); | ||
dataSource.setUser(CloudNotify.getInstance().getFileManager().getConfig().getString("MySQL.user")); | ||
dataSource.setPassword(CloudNotify.getInstance().getFileManager().getConfig().getString("MySQL.password")); | ||
dataSource.setDatabaseName(CloudNotify.getInstance().getFileManager().getConfig().getString("MySQL.databaseName")); | ||
dataSource.setServerName(CloudNotify.getInstance().getFileManager().getConfig().getString("MySQL.host")); | ||
dataSource.setPort(CloudNotify.getInstance().getFileManager().getConfig().getInt("MySQL.port")); | ||
execute("CREATE TABLE IF NOT EXISTS cloudNotify (uuid VARCHAR(128) NOT NULL, state BOOLEAN NOT NULL, PRIMARY KEY(uuid))"); | ||
} | ||
|
||
private void execute(String request) { | ||
try { | ||
Connection connection = dataSource.getConnection(); | ||
Statement statement = connection.createStatement(); | ||
statement.executeUpdate(request); | ||
|
||
statement.close(); | ||
connection.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public boolean notNull(UUID uuid) { | ||
try { | ||
Connection connection = dataSource.getConnection(); | ||
Statement statement = connection.createStatement(); | ||
ResultSet resultSet = statement.executeQuery("SELECT * FROM cloudNotify WHERE uuid='" + uuid.toString() + "'"); | ||
while (resultSet.next()) return true; | ||
|
||
resultSet.close(); | ||
statement.close(); | ||
connection.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
public void setNotifyState(UUID uuid, boolean b) { | ||
execute("REPLACE INTO cloudNotify (uuid, state) VALUES ('" + uuid.toString() + "', " + b + ")"); | ||
} | ||
|
||
public boolean getNotifyState(UUID uuid) { | ||
boolean state = false; | ||
|
||
try { | ||
Connection connection = dataSource.getConnection(); | ||
Statement statement = connection.createStatement(); | ||
ResultSet resultSet = statement.executeQuery("SELECT state FROM cloudNotify WHERE uuid='" + uuid.toString() + "'"); | ||
resultSet.next(); | ||
state = resultSet.getBoolean("state"); | ||
resultSet.close(); | ||
statement.close(); | ||
connection.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return state; | ||
} | ||
|
||
} |
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
10 changes: 4 additions & 6 deletions
10
src/main/java/cloud/timo/CloudNotify/managers/MessageManager.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 |
---|---|---|
@@ -1,16 +1,14 @@ | ||
package cloud.timo.CloudNotify.managers; | ||
|
||
import cloud.timo.CloudNotify.CloudNotify; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.ChatColor; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
|
||
public class MessageManager { | ||
|
||
public static void sendMessageToTeam(String message) { | ||
ProxyServer.getInstance().getPlayers().forEach(proxiedPlayer -> { | ||
if (proxiedPlayer.hasPermission("cloudnotify.notify")) | ||
proxiedPlayer.sendMessage(new TextComponent(CloudNotify.getInstance().getPrefix() + message)); | ||
}); | ||
public static void sendMessage(CommandSender proxiedPlayer, String message) { | ||
proxiedPlayer.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', CloudNotify.getInstance().getPrefix() + message))); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/cloud/timo/CloudNotify/managers/PluginMessageManager.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,18 @@ | ||
package cloud.timo.CloudNotify.managers; | ||
|
||
import cloud.timo.CloudNotify.CloudNotify; | ||
import cloud.timo.TimoCloud.api.TimoCloudAPI; | ||
import cloud.timo.TimoCloud.api.messages.listeners.MessageListener; | ||
import cloud.timo.TimoCloud.api.messages.objects.AddressedPluginMessage; | ||
|
||
public class PluginMessageManager implements MessageListener { | ||
|
||
public PluginMessageManager(){ | ||
TimoCloudAPI.getMessageAPI().registerMessageListener(this::onPluginMessage, "CLOUDNOTIFY_NOTIFICATION"); | ||
} | ||
|
||
@Override | ||
public void onPluginMessage(AddressedPluginMessage addressedPluginMessage) { | ||
CloudNotify.getInstance().getHelper().notify(addressedPluginMessage.getMessage()); | ||
} | ||
} |
Oops, something went wrong.