Skip to content

Commit

Permalink
Merge pull request #7 from eartho-project/main
Browse files Browse the repository at this point in the history
Update  to Version 0.1.5 and Support edit message webhook.yml
  • Loading branch information
Gl0W1E authored Mar 27, 2024
2 parents ea2a391 + be19020 commit 504b3a7
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 84 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: Java CI with Maven and GitHub Releases

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Project Version (project.version) To Environment
run: echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -24,3 +29,12 @@ jobs:
cache: maven
- name: Build with Maven
run: mvn -B -X package --file pom.xml

- name: Publish to GitHub Releases
uses: softprops/action-gh-release@v1
with:
files: target/*.jar
token: ${{ secrets.GITHUB_TOKEN }}
release_name: ${{ env.PROJECT_VERSION }}
tag_name: ${{ env.PROJECT_VERSION }}
overwrite: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ buildNumber.properties

# Common working directory
run/

.vscode
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
Minimum Towny Version: `0.100.0.0` \
Minimum SiegeWar Version: `2.9.0` \
Minimum Brewery Version: `3.1`


### Rework by [eartho-project](https://github.com/eartho-project) & [Aomkoyo](https://github.com/aomkoyo)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.darthpeti</groupId>
<artifactId>TownyTweaks</artifactId>
<version>0.1.4</version>
<version>0.1.5</version>
<packaging>jar</packaging>

<name>TownyTweaks</name>
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/me/darthpeti/townytweaks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void onEnable() {
createCustomConfig();
loadConfig();
registerListenersAndCommands();
log.info(prefix+" TownyTweaks has been enabled. (Version: "+instance.getDescription().getVersion()+" )");
log.info(prefix+" TownyTweaks is a Towny addon plugin, created by DarthPeti. rework by: @Aomkoyo");
}

public void createCustomConfig(){
Expand All @@ -56,6 +58,10 @@ public void createCustomConfig(){
}
}

public void reloadCustomConfig(){
customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
}

public FileConfiguration getCustomConfig() {
return this.customConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,36 @@ public class TownyTweaks implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(args.length > 0){
if(args[0].equalsIgnoreCase("reload")){
Main.getInstance().reloadConfig();
if(sender instanceof Player){
sender.sendMessage(Main.prefix + "Configuration Reloaded.");
return true;
} else {
Main.log.info("TownyTweaks Config Reloaded");
return true;
}
switch (args[0].toLowerCase()) {
case "reload":
Main.getInstance().reloadCustomConfig();
if(sender instanceof Player){
sender.sendMessage(Main.prefix + "Configuration Reloaded., if no changes are visible, please restart the server or use plugman to reload the plugin.");
return true;
} else {
Main.log.info("Configuration Reloaded., if no changes are visible, please restart the server or use plugman to reload the plugin.");
return true;
}
case "version":
if(sender instanceof Player){
sender.sendMessage(Main.prefix + "TownyTweaks Version: " + Main.getInstance().getDescription().getVersion() + " by DarthPeti, rework by: @Aomkoyo");
return true;
} else {
Main.log.info("TownyTweaks Version: " + Main.getInstance().getDescription().getVersion()+ " by DarthPeti, rework by: @Aomkoyo");
return true;
}
default:
if (sender instanceof Player) {
sender.sendMessage(Main.prefix + "TownyTweaks Help:");
sender.sendMessage(Main.prefix + "/townytweaks reload - Reloads the configuration file.");
sender.sendMessage(Main.prefix + "/townytweaks version - Shows the version of the plugin.");
return true;
} else {
Main.log.info("TownyTweaks Help:");
Main.log.info("/townytweaks reload - Reloads the configuration file.");
Main.log.info("/townytweaks version - Shows the version of the plugin.");
return true;
}
}
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.palmergames.bukkit.towny.event.DeleteNationEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -19,14 +21,21 @@ public DeletedNation(Logger logger) {

@EventHandler
public void onTown(DeleteNationEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-nation-disband").equalsIgnoreCase("true")) {
String PrefixConfigName = "nation-disband";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
String nationName = event.getNationName();
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription("The nation of " + nationName + " has disbanded!")
);
DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook-url"));
String messageConfig = config.getString("message-" + PrefixConfigName).replace("{nationName}", nationName);
if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}

try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.palmergames.bukkit.towny.event.DeleteTownEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -19,14 +21,20 @@ public DeletedTown(Logger logger) {

@EventHandler
public void onTown(DeleteTownEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-town-delete").equalsIgnoreCase("true")) {
String PrefixConfigName = "town-delete";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
String townName = event.getTownName();
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription("The town of " + townName + " has been deleted!")
);
DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook-url"));
String messageConfig = config.getString("message-" + PrefixConfigName).replace("{townName}", townName);
if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}
try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.palmergames.bukkit.towny.event.NewNationEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -19,15 +21,22 @@ public NewNation(Logger logger) {

@EventHandler
public void onTown(NewNationEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-nation-create").equalsIgnoreCase("true")) {
// nation-create
String PrefixConfigName = "nation-create";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
String nationName = event.getNation().getName();
String kingName = event.getNation().getKing().getName();
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(0, 81, 255))
.setDescription(kingName + " has made a new nation called " + nationName + "!")
);
String messageConfig = config.getString("message-" + PrefixConfigName).replace("{nationName}", nationName).replace("{kingName}", kingName);
if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(0, 81, 255))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}
try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import com.palmergames.bukkit.towny.event.NewTownEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;


import java.awt.*;
import java.util.logging.Logger;


public class NewTown implements Listener {

private Logger logger;
Expand All @@ -21,15 +21,23 @@ public NewTown(Logger logger) {

@EventHandler
public void onTown(NewTownEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-town-creation").equalsIgnoreCase("true")) {
String PrefixConfigName = "town-creation";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
String townName = event.getTown().getName();
String mayorName = event.getTown().getMayor().getName();
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));
DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook-url"));
String messageConfig = config.getString("message-" + PrefixConfigName).replace("{townName}", townName).replace("{mayorName}", mayorName);

if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(0, 81, 255))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(0, 81, 255))
.setDescription(mayorName + " has created a new town called " + townName + "!")
);
try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.palmergames.bukkit.towny.event.town.TownRuinedEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -19,14 +21,21 @@ public RuinedTown(Logger logger) {

@EventHandler
public void onTown(TownRuinedEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-town-ruins").equalsIgnoreCase("true")) {
// town-ruins
String PrefixConfigName = "town-ruins";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
String townName = event.getTown().getName();
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(255, 0, 47))
.setDescription("The town of " + townName + " has fallen into ruins!")
);
DiscordWebhook webhook = new DiscordWebhook(config.getString("webhook-url"));
String messageConfig = config.getString("message-" + PrefixConfigName).replace("{townName}", townName);
if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}
try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.gmail.goosius.siegewar.events.BattleSessionEndedEvent;
import me.darthpeti.townytweaks.Main;
import me.darthpeti.townytweaks.towny.util.DiscordWebhook;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

Expand All @@ -19,14 +21,20 @@ public SiegeSessionEnd(Logger logger) {

@EventHandler
public void onTown(BattleSessionEndedEvent event) {
if (Main.getInstance().getCustomConfig().getString("notification-siegewar-session-end").equalsIgnoreCase("true")) {

// siegewar-session-end
String PrefixConfigName = "siegewar-session-end";
FileConfiguration config = Main.getInstance().getCustomConfig();
if (config.getString("notification-"+PrefixConfigName).equalsIgnoreCase("true")) {
DiscordWebhook webhook = new DiscordWebhook(Main.getInstance().getCustomConfig().getString("webhook-url"));

webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(255, 157, 0))
.setDescription("The current battle session has ended!")
);
String messageConfig = config.getString("message-" + PrefixConfigName);
if (config.getString("embed-" + PrefixConfigName).equalsIgnoreCase("true")) {
webhook.addEmbed(new DiscordWebhook.EmbedObject()
.setColor(new Color(214, 99, 84))
.setDescription(messageConfig)
);
} else {
webhook.setContent(messageConfig);
}
try {
webhook.execute();
} catch (java.io.IOException e) {
Expand Down
Loading

0 comments on commit 504b3a7

Please sign in to comment.