Skip to content

Commit

Permalink
Merge pull request #15 from ivall/debug-logging
Browse files Browse the repository at this point in the history
Add debug logging capability
  • Loading branch information
ivall authored Jan 16, 2023
2 parents 2cc59f0 + c9eed42 commit e4b58d7
Show file tree
Hide file tree
Showing 24 changed files with 434 additions and 119 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# VIshop-plugin
Plugin łączący serwer Minecraft z itemshopem stworzonym na [VIshop.pl](https://vishop.pl/)
Plugin łączący serwer Minecraft z itemshopem stworzonym na [VIshop.pl](https://vishop.pl/)
Wspierane (przetestowane przez autorów) wersje Minecrafta — od 1.8 do 1.19.3

Plugin przeznaczony dla platform:
- pochodnych Bukkita (Spigot, Paper, itp.)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ allprojects {
apply plugin: 'com.github.johnrengelman.shadow'

group = 'pl.vishop.plugin'
version = '2.2'
version = '2.3'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 VIshop-plugin Contributors
* https://github.com/ivall/VIshop-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.vishop.plugin.bukkit;

import org.bukkit.configuration.ConfigurationSection;
import pl.vishop.plugin.config.ConfigLoader;

public class BukkitConfigLoader implements ConfigLoader {

private final ConfigurationSection configFile;

public BukkitConfigLoader(final ConfigurationSection configFile) {
this.configFile = configFile;
}

@Override
public boolean getBoolean(final String key) {
return this.configFile.getBoolean(key);
}

@Override
public String getString(final String key) {
return this.configFile.getString(key);
}

}
15 changes: 3 additions & 12 deletions bukkit/src/main/java/pl/vishop/plugin/bukkit/BukkitOrderTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,18 @@
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import pl.vishop.plugin.config.Config;
import pl.vishop.plugin.logger.ViShopLogger;
import pl.vishop.plugin.order.OrderTask;

public class BukkitOrderTask extends OrderTask {

private final Plugin plugin;

public BukkitOrderTask(final Plugin plugin, final OkHttpClient httpClient, final Config config) {
super(httpClient, config);
public BukkitOrderTask(final Plugin plugin, final OkHttpClient httpClient, final Config config, final ViShopLogger logger) {
super(httpClient, config, logger);
this.plugin = plugin;
}

@Override
public void logInfo(final String message) {
this.plugin.getLogger().info(message);
}

@Override
public void logError(final String message) {
this.plugin.getLogger().severe(message);
}

@Override
public boolean isPlayerOnline(final String playerName) {
return Bukkit.getPlayerExact(playerName) != null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2022 VIshop-plugin Contributors
* https://github.com/ivall/VIshop-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.vishop.plugin.bukkit;

import java.util.logging.Logger;
import pl.vishop.plugin.logger.ViShopLogger;

public class BukkitViShopLogger implements ViShopLogger {

private final Logger logger;

public BukkitViShopLogger(final Logger logger) {
this.logger = logger;
}

@Override
public void info(final String message) {
this.logger.info(message);
}

@Override
public void error(final String message) {
this.logger.severe(message);
}

@Override
public void debug(final String message) {
this.logger.info(String.format("[DEBUG] %s", message));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

import okhttp3.OkHttpClient;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import pl.vishop.plugin.config.Config;
import pl.vishop.plugin.config.EmptyConfigFieldException;
import pl.vishop.plugin.logger.ViShopLogger;

public final class BukkitViShopPlugin extends JavaPlugin {

Expand All @@ -32,22 +32,20 @@ public final class BukkitViShopPlugin extends JavaPlugin {
public void onEnable() {
this.saveDefaultConfig();

final Config config;
try {
final FileConfiguration cfgFile = this.getConfig();
config = new Config(cfgFile.getString("apiKey"), cfgFile.getString("shopId"), cfgFile.getString("serverId"));
final Config config = new Config(new BukkitConfigLoader(this.getConfig()));
final ViShopLogger logger = new BukkitViShopLogger(this.getLogger());

Bukkit.getScheduler().runTaskTimerAsynchronously(
this,
new BukkitOrderTask(this, this.httpClient, config, logger),
0L,
config.taskInterval.getSeconds() * 20L
);
} catch (final EmptyConfigFieldException exception) {
this.getLogger().severe(exception.getMessage());
Bukkit.getPluginManager().disablePlugin(this);
return;
}

Bukkit.getScheduler().runTaskTimerAsynchronously(
this,
new BukkitOrderTask(this, this.httpClient, config),
0L,
config.taskInterval.getSeconds() * 20L
);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion bukkit/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ViShopPlugin
version: '2.2'
version: '2.3'
api-version: 1.13
main: pl.vishop.plugin.bukkit.BukkitViShopPlugin
description: "Wykonuj zamówienia ze swojego sklepu ViShop"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 VIshop-plugin Contributors
* https://github.com/ivall/VIshop-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.vishop.plugin.bungee;

import net.md_5.bungee.config.Configuration;
import pl.vishop.plugin.config.ConfigLoader;

public class BungeeConfigLoader implements ConfigLoader {

private final Configuration configFile;

public BungeeConfigLoader(final Configuration configFile) {
this.configFile = configFile;
}

@Override
public boolean getBoolean(final String key) {
return this.configFile.getBoolean(key);
}

@Override
public String getString(final String key) {
return this.configFile.getString(key);
}

}
21 changes: 4 additions & 17 deletions bungee/src/main/java/pl/vishop/plugin/bungee/BungeeOrderTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,19 @@

package pl.vishop.plugin.bungee;

import java.util.logging.Logger;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
import okhttp3.OkHttpClient;
import pl.vishop.plugin.config.Config;
import pl.vishop.plugin.logger.ViShopLogger;
import pl.vishop.plugin.order.OrderTask;

public class BungeeOrderTask extends OrderTask {

private final ProxyServer proxy;
private final Logger logger;

public BungeeOrderTask(final Plugin plugin, final OkHttpClient httpClient, final Config config) {
super(httpClient, config);
this.proxy = plugin.getProxy();
this.logger = plugin.getLogger();
}

@Override
public void logInfo(final String message) {
this.logger.info(message);
}

@Override
public void logError(final String message) {
this.logger.severe(message);
public BungeeOrderTask(final OkHttpClient httpClient, final Config config, final ViShopLogger logger) {
super(httpClient, config, logger);
this.proxy = ProxyServer.getInstance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2022 VIshop-plugin Contributors
* https://github.com/ivall/VIshop-plugin/graphs/contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package pl.vishop.plugin.bungee;

import java.util.logging.Logger;
import pl.vishop.plugin.logger.ViShopLogger;

public class BungeeViShopLogger implements ViShopLogger {

private final Logger logger;

public BungeeViShopLogger(final Logger logger) {
this.logger = logger;
}

@Override
public void info(final String message) {
this.logger.info(message);
}

@Override
public void error(final String message) {
this.logger.severe(message);
}

@Override
public void debug(final String message) {
this.logger.info(String.format("[DEBUG] %s", message));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import okhttp3.OkHttpClient;
import pl.vishop.plugin.config.Config;
import pl.vishop.plugin.config.EmptyConfigFieldException;
import pl.vishop.plugin.logger.ViShopLogger;
import pl.vishop.plugin.resource.ResourceLoader;
import pl.vishop.plugin.resource.ResourceLoaderException;

Expand All @@ -39,23 +40,21 @@ public void onEnable() {
return;
}

final Configuration cfgFile = resourceLoader.load("config.yml");
final Config config;

try {
config = new Config(cfgFile.getString("apiKey"), cfgFile.getString("shopId"), cfgFile.getString("serverId"));
final Configuration cfgFile = resourceLoader.load("config.yml");
final Config config = new Config(new BungeeConfigLoader(cfgFile));
final ViShopLogger logger = new BungeeViShopLogger(this.getLogger());

this.getProxy().getScheduler().schedule(
this,
new BungeeOrderTask(this.httpClient, config, logger),
0L,
config.taskInterval.getSeconds(),
TimeUnit.SECONDS
);
} catch (final EmptyConfigFieldException exception) {
this.getLogger().severe(exception.getMessage());
return;
}

this.getProxy().getScheduler().schedule(
this,
new BungeeOrderTask(this, this.httpClient, config),
0L,
config.taskInterval.getSeconds(),
TimeUnit.SECONDS
);
} catch (final ResourceLoaderException exception) {
this.getLogger().severe(exception.getReason().getMessage("config.yml"));
this.getLogger().severe("Przyczyna: " + exception.getCause().getMessage());
Expand Down
2 changes: 1 addition & 1 deletion bungee/src/main/resources/bungee.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ViShopPlugin
version: '2.2'
version: '2.3'
api-version: 1.13
main: pl.vishop.plugin.bungee.BungeeViShopPlugin
description: "Wykonuj zamówienia ze swojego sklepu ViShop"
Expand Down
10 changes: 6 additions & 4 deletions common/src/main/java/pl/vishop/plugin/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ public class Config {
public final String apiKey;
public final String shopId;
public final String serverId;
public final boolean debug;

public final Duration taskInterval = Duration.of(30, ChronoUnit.SECONDS);

public Config(final String apiKey, final String shopId, final String serverId) throws EmptyConfigFieldException {
this.apiKey = apiKey;
this.shopId = shopId;
this.serverId = serverId;
public Config(final ConfigLoader loader) throws EmptyConfigFieldException {
this.apiKey = loader.getString("apiKey");
this.shopId = loader.getString("shopId");
this.serverId = loader.getString("serverId");
this.debug = loader.getBoolean("debug");
this.checkValues();
}

Expand Down
Loading

0 comments on commit e4b58d7

Please sign in to comment.