Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 38 additions & 12 deletions src/main/java/ecb/ajneb97/core/managers/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

public class ConfigManager {
Expand All @@ -17,14 +20,14 @@ public class ConfigManager {
private String originalFileName;
private String newFileName;

public ConfigManager(Path dataDirectoryPath,String originalFileName,String newFileName){
public ConfigManager(Path dataDirectoryPath, String originalFileName, String newFileName) {
this.dataDirectoryPath = dataDirectoryPath;
this.originalFileName = originalFileName;
this.newFileName = newFileName;
}

public void registerConfig() {
String path = dataDirectoryPath+File.separator+newFileName;
String path = dataDirectoryPath + File.separator + newFileName;
createDefaultConfigFile();

yamlFile = new YamlFile(path);
Expand All @@ -39,14 +42,14 @@ public void registerConfig() {
}
}

public void createDefaultConfigFile(){
public void createDefaultConfigFile() {
File dataDirectoryFile = new File(dataDirectoryPath.toString());
if (!dataDirectoryFile.exists()){
if (!dataDirectoryFile.exists()) {
dataDirectoryFile.mkdir();
}
File configFile = new File(dataDirectoryFile, newFileName);
try {
if (!configFile.exists()){
if (!configFile.exists()) {
Files.copy(this.getClass().getClassLoader().getResourceAsStream(originalFileName), configFile.toPath());
}
} catch (IOException e) {
Expand All @@ -59,21 +62,33 @@ public YamlFile getConfig() {
}

public void checkMessagesUpdate() {
Path configFile = Paths.get(dataDirectoryPath+File.separator+newFileName);
Path configFile = Paths.get(dataDirectoryPath + File.separator + newFileName);
try {
String configText = new String(Files.readAllBytes(configFile));
if(!configText.contains("custom_commands_actions:")){
List<String> list = new ArrayList<String>();
if (!yamlFile.contains("actions.enabled")) {
yamlFile.set("actions.enabled", true);
yamlFile.save();
yamlFile.load();
}

if (!yamlFile.contains("actions.key")) {
yamlFile.set("actions.key", generateKey(16));
yamlFile.save();
yamlFile.load();
}

if (!configText.contains("custom_commands_actions:")) {
List<String> list = new ArrayList<>();
list.add("/bungee");
yamlFile.set("custom_commands_actions.example1.commands", list);
list = new ArrayList<String>();
list = new ArrayList<>();
list.add("message: &8[&b&lECB&8] &cYou can't see the BungeeCord version!");
yamlFile.set("custom_commands_actions.example1.actions", list);
yamlFile.save();
yamlFile.load();
}

if(!configText.contains("blocked_command_default_actions:")){
if (!configText.contains("blocked_command_default_actions:")) {
List<String> list = new ArrayList<String>();
list.add("message: &8[&b&lECB&8] &cYou don't have permissions to use that command.");
list.add("playsound: BLOCK_NOTE_BLOCK_PLING;10;0.1");
Expand All @@ -82,8 +97,19 @@ public void checkMessagesUpdate() {
yamlFile.save();
yamlFile.load();
}
}catch(IOException e){
e.printStackTrace();
} catch (IOException | NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}

public String generateKey(int length) throws NoSuchAlgorithmException {
SecureRandom secureRandom = new SecureRandom();
byte[] key = new byte[length];
secureRandom.nextBytes(key);
return Base64.getEncoder().encodeToString(key);
}

public YamlFile getYamlFile() {
return yamlFile;
}
}
8 changes: 7 additions & 1 deletion src/main/java/ecb/ajneb97/spigot/EasyCommandBlocker.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public void onEnable(){
commandsManager = new CommandsManager(configManager.getConfig());
registerCommands();
registerEvents();
bungeeMessagingManager = new BungeeMessagingManager(this);
if (configManager.getYamlFile().get("settings.bungeecord") != null && configManager.getYamlFile().getBoolean("settings.bungeecord")) {
bungeeMessagingManager = new BungeeMessagingManager(this);
}
protocolLibManager = new ProtocolLibManager(this);
viaVersionManager = new ViaVersionManager(this);

Expand Down Expand Up @@ -79,6 +81,10 @@ public void registerCommands(){
this.getCommand("ecb").setExecutor(new MainCommand(this));
}

public ConfigManager getConfigManager() {
return configManager;
}

public void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerListener(this), this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
public class BungeeMessagingManager implements PluginMessageListener {

private EasyCommandBlocker plugin;
public BungeeMessagingManager(EasyCommandBlocker plugin){
if (!Bukkit.getServer().spigot().getConfig().getBoolean( "settings.bungeecord" ) ) {

public BungeeMessagingManager(EasyCommandBlocker plugin) {
this.plugin = plugin;

if (!Bukkit.getServer().spigot().getConfig().getBoolean("settings.bungeecord")) {
return;
}

Expand All @@ -22,16 +25,25 @@ public BungeeMessagingManager(EasyCommandBlocker plugin){

@Override
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
if(!channel.equalsIgnoreCase(GlobalVariables.bungeeMainChannel)) {
if (!channel.equalsIgnoreCase(GlobalVariables.bungeeMainChannel)) {
return;
}

ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF();
if(subChannel.equalsIgnoreCase( GlobalVariables.bungeeActionsSubChannel)) {
String data = in.readUTF();

ActionsUtils.executeAction(data,player);
String key = in.readUTF();
if (!plugin.getConfigManager().getYamlFile().contains("actions.key")) {
plugin.getLogger().warning("No key found in config.yml, but continue..");
}
if (!key.equals(plugin.getConfigManager().getYamlFile().getString("actions.key"))) {
plugin.getLogger().warning("Player attempting password bypass: " + player.getName() + ":" + player.getUniqueId());
return;
}

if (subChannel.equalsIgnoreCase(GlobalVariables.bungeeActionsSubChannel)) {
String data = in.readUTF();
ActionsUtils.executeAction(data, player);
}
}
}