Skip to content

Commit

Permalink
Merge pull request #21 from SmartGecko44/experimental
Browse files Browse the repository at this point in the history
Fixed workflows, config now gets saved, misc
  • Loading branch information
SmartGecko44 authored Dec 3, 2023
2 parents 6c94ebe + e2b94a0 commit 1cecad0
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 56 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ jobs:
- name: Build with Maven
run: mvn package --file ../pom.xml
working-directory: target

- name: Create filtered-artifacts
run: mkdir -p filtered-artifacts

- name: Filter and Upload JAR as an artifact
run: |
# Filter out files that start with 'Wauh' and upload the rest
find -type f -name Wauh*.jar -exec cp {} filtered-artifacts/ \;
- name: Upload JAR as an artifact
uses: actions/upload-artifact@v2
with:
name: Wauh-${{ github.run_number }}
path: filtered-artifacts
if-no-files-found: error
96 changes: 52 additions & 44 deletions src/main/java/org/gecko/wauh/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,92 @@

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.wauh.data.ConfigurationManager;
import org.gecko.wauh.listeners.*;
import org.gecko.wauh.commands.SetRadiusLimitCommand;
import org.gecko.wauh.commands.StopWauh;
import org.gecko.wauh.commands.ToggleRemovalView;
import org.gecko.wauh.logic.ScaleReverse;

public final class Main extends JavaPlugin {

private int playerRadiusLimit = 20;
private int tntRadiusLimit = 5;
private int creeperRadiusLimit = 0;
private int playerRadiusLimit;
private int tntRadiusLimit;
private int creeperRadiusLimit;
private boolean showRemoval = true;
private BucketListener bucketListener;
private BarrierListener barrierListener;
private BedrockListener bedrockListener;
private WaterBucketListener waterBucketListener;
private TNTListener tntListener;
private CreeperListener creeperListener;
private ScaleReverse scaleReverse;
private ConfigurationManager configManager;
private FileConfiguration config;

@Override
public void onEnable() {
// Plugin startup logic
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Yay");

// Create instances of the listeners
bucketListener = new BucketListener();
barrierListener = new BarrierListener();
bedrockListener = new BedrockListener();
waterBucketListener = new WaterBucketListener();
tntListener = new TNTListener();
creeperListener = new CreeperListener();
configManager = new ConfigurationManager(Main.getPlugin(Main.class));
config = configManager.getConfig();

// Register the listeners
getServer().getPluginManager().registerEvents(bucketListener, this);
getServer().getPluginManager().registerEvents(barrierListener, this);
getServer().getPluginManager().registerEvents(bedrockListener, this);
getServer().getPluginManager().registerEvents(waterBucketListener, this);
getServer().getPluginManager().registerEvents(tntListener, this);
getServer().getPluginManager().registerEvents(creeperListener, this);

// Register the StopWauh command with the listeners as arguments
this.getCommand("stopwauh").setExecutor(new StopWauh(bucketListener, barrierListener, bedrockListener, waterBucketListener));
this.getCommand("setradiuslimit").setExecutor(new SetRadiusLimitCommand(this));
this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this));
this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this));
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

public int getRadiusLimit() {
playerRadiusLimit = config.getInt("playerRadiusLimit", playerRadiusLimit);
return playerRadiusLimit + 2;
}

public void setRadiusLimit(int newLimit) {
playerRadiusLimit = newLimit;
config.set("playerRadiusLimit", playerRadiusLimit);
configManager.saveConfig();
}
public int getTntRadiusLimit() {
tntRadiusLimit = config.getInt("tntRadiusLimit", tntRadiusLimit);
return tntRadiusLimit + 2;
}
public void setTntRadiusLimit(int newLimit) {
tntRadiusLimit = newLimit;
config.set("tntRadiusLimit", tntRadiusLimit);
configManager.saveConfig();
}
public int getCreeperRadiusLimit() {
creeperRadiusLimit = config.getInt("creeperRadiusLimit", creeperRadiusLimit);
return creeperRadiusLimit + 2;
}
public void setCreeperLimit(int newLimit) {
creeperRadiusLimit = newLimit;
config.set("creeperRadiusLimit", creeperRadiusLimit);
configManager.saveConfig();
}
public boolean getShowRemoval() {
return showRemoval;
Expand Down Expand Up @@ -71,43 +118,4 @@ public TNTListener getTntListener() {
public CreeperListener getCreeperListener() {
return creeperListener;
}
public ScaleReverse getScaleReverse() {
return scaleReverse;
}

@Override
public void onEnable() {
// Plugin startup logic
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.AQUA + "Yay");

// Create instances of the listeners
bucketListener = new BucketListener();
barrierListener = new BarrierListener();
bedrockListener = new BedrockListener();
waterBucketListener = new WaterBucketListener();
tntListener = new TNTListener();
creeperListener = new CreeperListener();

// Register the listeners
getServer().getPluginManager().registerEvents(bucketListener, this);
getServer().getPluginManager().registerEvents(barrierListener, this);
getServer().getPluginManager().registerEvents(bedrockListener, this);
getServer().getPluginManager().registerEvents(waterBucketListener, this);
getServer().getPluginManager().registerEvents(tntListener, this);
getServer().getPluginManager().registerEvents(creeperListener, this);

// Register the StopWauh command with the listeners as arguments
this.getCommand("stopwauh").setExecutor(new StopWauh(bucketListener, barrierListener, bedrockListener, waterBucketListener));
this.getCommand("setradiuslimit").setExecutor(new SetRadiusLimitCommand(this));
this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this));
this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this));
}

@Override
public void onDisable() {
// Plugin shutdown logic
Bukkit.getConsoleSender().sendMessage("");
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "kys");
}
}
51 changes: 39 additions & 12 deletions src/main/java/org/gecko/wauh/data/ConfigurationManager.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,56 @@
/*package org.gecko.wauh.data;
package org.gecko.wauh.data;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.file.FileConfiguration;
import org.gecko.wauh.Main;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ConfigurationManager {
private final Main plugin;
private final File configFile;
private FileConfiguration config;
private final Logger logger = Logger.getLogger(Main.class.getName());
public ConfigurationManager(Main plugin) {
this.plugin = plugin;
this.configFile = new File(plugin.getDataFolder(), "data.yml");
File dir = new File("plugins/Wauh");

if (!dir.exists()) {
boolean dirCreated = dir.mkdirs();

// Create the data.yml file if it doesn't exist
if (!configFile.exists()) {
plugin.saveResource("data.yml", false);
if (!dirCreated) {
plugin.getLogger().log(Level.SEVERE, "Config folder could not be created");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config folder created!");
}
}

// Load the config
this.config = YamlConfiguration.loadConfiguration(configFile);
this.configFile = new File(dir, "data.yml");

try {
// Create the data.yml file if it doesn't exist
if (!configFile.exists()) {
boolean fileCreated = configFile.createNewFile();
if (!fileCreated) {
logger.log(Level.SEVERE, "Config file could not be created");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!");
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20 \n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 0\n");
writer.close();
}
}

this.config = YamlConfiguration.loadConfiguration(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not load config file", ex);
}
}

public FileConfiguration getConfig() {
Expand All @@ -33,9 +61,8 @@ public void saveConfig() {
try {
config.save(configFile);
} catch (IOException e) {
e.printStackTrace();
logger.log(Level.SEVERE, "Unable to save config", e);
}
}

}
*/

0 comments on commit 1cecad0

Please sign in to comment.