Skip to content

Commit 990173e

Browse files
committed
Code cleanup
1 parent 73a6c34 commit 990173e

File tree

9 files changed

+47
-35
lines changed

9 files changed

+47
-35
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ public class MyListener implements Listener {
150150

151151
// Identifier of the sender server.
152152
String senderServerId = event.getSenderIdentifier();
153+
154+
// Date when the message was sent
155+
long timestamp = event.getTimeStamp();
153156

154157
// Text of the message received.
155158
String messageText = event.getMessage();
@@ -232,7 +235,7 @@ public class MyExamplePlugin extends JavaPlugin implements IForestRedisPlugin {
232235

233236
@Override
234237
@SuppressWarnings("Called asynchronously!")
235-
public void callEvent(String channel, MessageTransferObject messageTransferObject) {
238+
public void onMessageReceived(String channel, MessageTransferObject messageTransferObject) {
236239
// Async call - what shall be done when the message arrives
237240
// You can completely remove lines below, but then built-in events won't work
238241
Bukkit.getPluginManager().callEvent(new AsyncRedisMessageReceivedEvent(channel, messageTransferObject));

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.example</groupId>
88
<artifactId>ForestRedisAPI</artifactId>
9-
<version>1.0.4</version>
9+
<version>1.0.5</version>
1010

1111
<properties>
1212
<maven.compiler.source>11</maven.compiler.source>

src/main/java/cz/foresttech/forestredis/bungee/ForestRedisBungee.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package cz.foresttech.forestredis.bungee;
22

33
import cz.foresttech.forestredis.bungee.commands.BungeeForestRedisCommand;
4-
import cz.foresttech.forestredis.bungee.config.BungeeConfigAdapter;
4+
import cz.foresttech.forestredis.bungee.adapter.BungeeConfigAdapter;
55
import cz.foresttech.forestredis.bungee.events.RedisMessageReceivedEvent;
66
import cz.foresttech.forestredis.shared.*;
7-
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
7+
import cz.foresttech.forestredis.shared.adapter.IConfigurationAdapter;
88
import cz.foresttech.forestredis.shared.models.MessageTransferObject;
99
import net.md_5.bungee.api.ProxyServer;
1010
import net.md_5.bungee.api.plugin.Plugin;
@@ -37,7 +37,7 @@ public void runAsync(Runnable task) {
3737
}
3838

3939
@Override
40-
public void callEvent(String channel, MessageTransferObject messageTransferObject) {
40+
public void onMessageReceived(String channel, MessageTransferObject messageTransferObject) {
4141
ProxyServer.getInstance().getPluginManager().callEvent(new RedisMessageReceivedEvent(channel, messageTransferObject));
4242
}
4343

@@ -48,7 +48,7 @@ public Logger logger() {
4848

4949
@Override
5050
public IConfigurationAdapter getConfigAdapter() {
51-
BungeeConfigAdapter bungeeConfigAdapter = new BungeeConfigAdapter();
51+
BungeeConfigAdapter bungeeConfigAdapter = new BungeeConfigAdapter(this);
5252
bungeeConfigAdapter.setup("config");
5353
return bungeeConfigAdapter;
5454
}

src/main/java/cz/foresttech/forestredis/bungee/config/BungeeConfigAdapter.java renamed to src/main/java/cz/foresttech/forestredis/bungee/adapter/BungeeConfigAdapter.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package cz.foresttech.forestredis.bungee.config;
1+
package cz.foresttech.forestredis.bungee.adapter;
22

3-
import cz.foresttech.forestredis.bungee.ForestRedisBungee;
4-
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
3+
import cz.foresttech.forestredis.shared.adapter.IConfigurationAdapter;
4+
import net.md_5.bungee.api.plugin.Plugin;
55
import net.md_5.bungee.config.Configuration;
66
import net.md_5.bungee.config.ConfigurationProvider;
77
import net.md_5.bungee.config.YamlConfiguration;
@@ -14,24 +14,29 @@
1414

1515
public class BungeeConfigAdapter implements IConfigurationAdapter {
1616

17+
private final Plugin plugin;
1718
private String fileName;
1819
private Configuration configuration;
1920

21+
public BungeeConfigAdapter(Plugin plugin) {
22+
this.plugin = plugin;
23+
}
24+
2025
@Override
2126
public void setup(String fileName) {
2227
this.fileName = fileName;
2328

24-
if (!ForestRedisBungee.getInstance().getDataFolder().exists()) {
25-
ForestRedisBungee.getInstance().getDataFolder().mkdir();
29+
if (!plugin.getDataFolder().exists()) {
30+
plugin.getDataFolder().mkdir();
2631
}
2732

28-
File file = new File(ForestRedisBungee.getInstance().getDataFolder(), fileName + ".yml");
33+
File file = new File(plugin.getDataFolder(), fileName + ".yml");
2934

3035
if (!file.exists()) {
31-
try (InputStream in = ForestRedisBungee.getInstance().getResourceAsStream(fileName + ".yml")) {
36+
try (InputStream in = plugin.getResourceAsStream(fileName + ".yml")) {
3237
Files.copy(in, file.toPath());
3338
} catch (IOException e) {
34-
ForestRedisBungee.getInstance().logger().warning("Cannot create config.yml! This proxy won't process any Redis communication!");
39+
plugin.getLogger().warning("Cannot create config.yml! This proxy won't process any Redis communication!");
3540
return;
3641
}
3742
loadConfiguration();
@@ -49,9 +54,9 @@ public void loadConfiguration() {
4954
try {
5055
configuration = ConfigurationProvider
5156
.getProvider(YamlConfiguration.class)
52-
.load(new File(ForestRedisBungee.getInstance().getDataFolder(), fileName + ".yml"));
57+
.load(new File(plugin.getDataFolder(), fileName + ".yml"));
5358
} catch (IOException e) {
54-
ForestRedisBungee.getInstance().logger().warning("Cannot load config.yml! This proxy won't process any Redis communication!");
59+
plugin.getLogger().warning("Cannot load config.yml! This proxy won't process any Redis communication!");
5560
configuration = null;
5661
}
5762
}

src/main/java/cz/foresttech/forestredis/shared/IForestRedisPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cz.foresttech.forestredis.shared;
22

3-
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
3+
import cz.foresttech.forestredis.shared.adapter.IConfigurationAdapter;
44
import cz.foresttech.forestredis.shared.models.MessageTransferObject;
55
import cz.foresttech.forestredis.shared.models.RedisConfiguration;
66

@@ -29,7 +29,7 @@ public interface IForestRedisPlugin {
2929
* @param channel
3030
* @param messageTransferObject
3131
*/
32-
void callEvent(String channel, MessageTransferObject messageTransferObject);
32+
void onMessageReceived(String channel, MessageTransferObject messageTransferObject);
3333

3434
/*----------------------------------------------------------------------------------------------------------*/
3535

src/main/java/cz/foresttech/forestredis/shared/RedisManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public void onMessage(String channel, String message) {
379379
return;
380380
}
381381

382-
RedisManager.this.plugin.callEvent(channel, messageTransferObject);
382+
RedisManager.this.plugin.onMessageReceived(channel, messageTransferObject);
383383
}
384384
}
385385

src/main/java/cz/foresttech/forestredis/shared/config/IConfigurationAdapter.java renamed to src/main/java/cz/foresttech/forestredis/shared/adapter/IConfigurationAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package cz.foresttech.forestredis.shared.config;
1+
package cz.foresttech.forestredis.shared.adapter;
22

33
import java.util.List;
44

src/main/java/cz/foresttech/forestredis/spigot/ForestRedisSpigot.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package cz.foresttech.forestredis.spigot;
22

33
import cz.foresttech.forestredis.shared.*;
4-
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
4+
import cz.foresttech.forestredis.shared.adapter.IConfigurationAdapter;
55
import cz.foresttech.forestredis.shared.models.MessageTransferObject;
66
import cz.foresttech.forestredis.spigot.commands.SpigotForestRedisCommand;
7-
import cz.foresttech.forestredis.spigot.config.SpigotConfigAdapter;
7+
import cz.foresttech.forestredis.spigot.adapter.SpigotConfigAdapter;
88
import cz.foresttech.forestredis.spigot.events.AsyncRedisMessageReceivedEvent;
99
import cz.foresttech.forestredis.spigot.events.RedisMessageReceivedEvent;
1010
import org.bukkit.Bukkit;
@@ -37,7 +37,7 @@ public void runAsync(Runnable task) {
3737
}
3838

3939
@Override
40-
public void callEvent(String channel, MessageTransferObject messageTransferObject) {
40+
public void onMessageReceived(String channel, MessageTransferObject messageTransferObject) {
4141
Bukkit.getPluginManager().callEvent(new AsyncRedisMessageReceivedEvent(channel, messageTransferObject));
4242
Bukkit.getScheduler().runTask(this, () -> Bukkit.getPluginManager().callEvent(new RedisMessageReceivedEvent(channel, messageTransferObject)));
4343
}
@@ -49,7 +49,7 @@ public Logger logger() {
4949

5050
@Override
5151
public IConfigurationAdapter getConfigAdapter() {
52-
SpigotConfigAdapter spigotConfigAdapter = new SpigotConfigAdapter();
52+
SpigotConfigAdapter spigotConfigAdapter = new SpigotConfigAdapter(this);
5353
spigotConfigAdapter.setup("config");
5454
return spigotConfigAdapter;
5555
}

src/main/java/cz/foresttech/forestredis/spigot/config/SpigotConfigAdapter.java renamed to src/main/java/cz/foresttech/forestredis/spigot/adapter/SpigotConfigAdapter.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package cz.foresttech.forestredis.spigot.config;
1+
package cz.foresttech.forestredis.spigot.adapter;
22

33
import com.google.common.base.Charsets;
4-
import cz.foresttech.forestredis.bungee.ForestRedisBungee;
5-
import cz.foresttech.forestredis.shared.config.IConfigurationAdapter;
6-
import cz.foresttech.forestredis.spigot.ForestRedisSpigot;
4+
import cz.foresttech.forestredis.shared.adapter.IConfigurationAdapter;
75
import org.bukkit.configuration.file.FileConfiguration;
86
import org.bukkit.configuration.file.YamlConfiguration;
7+
import org.bukkit.plugin.java.JavaPlugin;
98

109
import java.io.File;
1110
import java.io.InputStream;
@@ -14,22 +13,27 @@
1413

1514
public class SpigotConfigAdapter implements IConfigurationAdapter {
1615

16+
private final JavaPlugin plugin;
1717
private String fileName;
1818
private File file;
1919
private FileConfiguration configuration;
2020

21+
public SpigotConfigAdapter(JavaPlugin plugin) {
22+
this.plugin = plugin;
23+
}
24+
2125
@Override
2226
public void setup(String fileName) {
2327
this.fileName = fileName;
2428

25-
if (!ForestRedisSpigot.getInstance().getDataFolder().exists()) {
26-
ForestRedisSpigot.getInstance().getDataFolder().mkdir();
29+
if (!plugin.getDataFolder().exists()) {
30+
plugin.getDataFolder().mkdir();
2731
}
2832

29-
file = new File(ForestRedisSpigot.getInstance().getDataFolder() + "/" + fileName + ".yml");
33+
file = new File(plugin.getDataFolder() + "/" + fileName + ".yml");
3034
if (!file.exists()) {
31-
ForestRedisSpigot.getInstance().logger().info("config.yml does not exist! Creating a new one!");
32-
ForestRedisSpigot.getInstance().saveResource(fileName + ".yml", false);
35+
plugin.getLogger().info("config.yml does not exist! Creating a new one!");
36+
plugin.saveResource(fileName + ".yml", false);
3337
}
3438

3539
configuration = YamlConfiguration.loadConfiguration(file);
@@ -45,12 +49,12 @@ public boolean isSetup() {
4549
public void loadConfiguration() {
4650
try {
4751
configuration = YamlConfiguration.loadConfiguration(file);
48-
InputStream defConfigStream = ForestRedisSpigot.getInstance().getResource(fileName + ".yml");
52+
InputStream defConfigStream = plugin.getResource(fileName + ".yml");
4953
if (defConfigStream != null) {
5054
configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream, Charsets.UTF_8)));
5155
}
5256
} catch (Exception ex) {
53-
ForestRedisBungee.getInstance().logger().warning("Cannot load config.yml! This server won't process any Redis communication!");
57+
plugin.getLogger().warning("Cannot load config.yml! This server won't process any Redis communication!");
5458
configuration = null;
5559
}
5660
}

0 commit comments

Comments
 (0)