Skip to content

Commit

Permalink
Add language configuration to the plugin (#5)
Browse files Browse the repository at this point in the history
* Added a config.yml for the plugin to change deny message,

* Fixed the startup message version.

* Added some pom.xml stuff to overall make the plugin more up to date.

* Add the new language to the sent message.

* Load the config & pass instance to the event.

* Update README

Add a usage section

* Nevermind

* Update plugin version

* Add requested changes

* Remove un-needed line

* Reduce diff, alter code to set the deny claim message on load.

Co-authored-by: Llm Dl <[email protected]>
  • Loading branch information
ARR4NN and LlmDl authored Jul 22, 2022
1 parent 3ac6144 commit 4f5e0ac
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
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>dev.siris</groupId>
<artifactId>WorldGuard-Towny</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>

<repositories>
<repository>
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/TownyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import org.bukkit.event.Listener;

public class TownyListener implements Listener {
WorldGuardTowny plugin;

public TownyListener(WorldGuardTowny plugin) {
this.plugin = plugin;
}

@EventHandler
public void onTownCreate(PreNewTownEvent event) {
Expand Down Expand Up @@ -53,7 +58,7 @@ public void validateAction(Player player, Cancellable event) {
// Check the flag.
if (!set.testState(wgPlayer, WorldGuardTowny.getTownCreationAllowedFlag())) {
// Cancel Town creation
TownyMessaging.sendErrorMsg(player, "You're not allowed to claim in this region.");
TownyMessaging.sendErrorMsg(player, plugin.getDenyclaimMsg());
event.setCancelled(true);
}
}
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/WorldGuardTowny.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.registry.FlagConflictException;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;

import java.util.Objects;

import org.bukkit.ChatColor;
import org.bukkit.plugin.java.JavaPlugin;

public class WorldGuardTowny extends JavaPlugin {

private static StateFlag TOWN_CREATION_ALLOWED_FLAG;
public static WorldGuardTowny instance;
private String denyClaimMsg;

public static StateFlag getTownCreationAllowedFlag() {
return TOWN_CREATION_ALLOWED_FLAG;
Expand All @@ -17,8 +22,12 @@ public static StateFlag getTownCreationAllowedFlag() {
@Override
public void onEnable() {
instance = this;
this.getServer().getPluginManager().
registerEvents(new TownyListener(), this);
this.getServer().getPluginManager().registerEvents(new TownyListener(this), this);

// Config Initialisation
getConfig().options().copyDefaults();
saveDefaultConfig();
setDenyClaimMsg();
}

@Override
Expand Down Expand Up @@ -47,4 +56,12 @@ public void onLoad() {
public static WorldGuardTowny getInstance() {
return instance;
}

public String getDenyclaimMsg() {
return denyClaimMsg;
}

public void setDenyClaimMsg() {
this.denyClaimMsg = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(getConfig().getString("language.deny-claim")));
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language:
deny-claim: "&cYou're not allowed to claim in this region."

0 comments on commit 4f5e0ac

Please sign in to comment.