Skip to content

Commit

Permalink
get rid of /townytweaks set. register townytweaks command. update tow…
Browse files Browse the repository at this point in the history
…ny version. configurable prefix
  • Loading branch information
Gl0W1E committed Nov 27, 2022
1 parent 1b0f871 commit 8b20bf6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 117 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<dependency>
<groupId>com.github.TownyAdvanced</groupId>
<artifactId>Towny</artifactId>
<version>0.98.2.0</version>
<version>0.98.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/me/darthpeti/townytweaks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.palmergames.bukkit.towny.object.WorldCoord;
import me.darthpeti.townytweaks.towny.commands.TownyTweaks;
import me.darthpeti.townytweaks.towny.listeners.*;
import me.darthpeti.townytweaks.towny.listeners.Discord.*;
import org.bukkit.Bukkit;
Expand All @@ -20,7 +21,6 @@ public final class Main extends JavaPlugin {

public static Main instance;
public static Logger log = Bukkit.getLogger();
public static String prefix = "§e[§bTownyTweaks§e]:§f ";
public static final Cache<WorldCoord, Boolean> siegeZoneCache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build();
private File customConfigFile;
private FileConfiguration customConfig;
Expand All @@ -29,12 +29,15 @@ public static Main getInstance(){
return instance;
}

public static String prefix;

@Override
public void onEnable() {
instance = this;
prefix = instance.getConfig().getString("townytweaks-prefix");
createCustomConfig();
loadConfig();
registerListeners();
registerListenersAndCommands();
}

public void createCustomConfig(){
Expand All @@ -56,7 +59,7 @@ public FileConfiguration getCustomConfig() {
return this.customConfig;
}

public void registerListeners(){
public void registerListenersAndCommands(){
instance.getServer().getPluginManager().registerEvents(new ArmorStandRestriction(), instance);
instance.getServer().getPluginManager().registerEvents(new ShulkerRestriction(), instance);
instance.getServer().getPluginManager().registerEvents(new ShulkerRestrictionInteract(), instance);
Expand All @@ -71,6 +74,7 @@ public void registerListeners(){
instance.getServer().getPluginManager().registerEvents(new SiegeSessionEnd(getLogger()), instance);
instance.getServer().getPluginManager().registerEvents(new SiegeSessionStart(getLogger()), instance);
instance.getServer().getPluginManager().registerEvents(new SiegeStart(getLogger()), instance);
instance.getCommand("townytweaks").setExecutor(new TownyTweaks());
}

@Override
Expand All @@ -83,5 +87,4 @@ public void loadConfig(){
instance.saveDefaultConfig();
}


}
111 changes: 3 additions & 108 deletions src/main/java/me/darthpeti/townytweaks/towny/commands/TownyTweaks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,116 +15,11 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
Main.getInstance().reloadConfig();
if(sender instanceof Player){
sender.sendMessage(Main.prefix + "Configuration Reloaded.");
return true;
} else {
Main.log.info("Configuration Reloaded");
Main.log.info("TownyTweaks Config Reloaded");
return true;
}
} else if(args[0].equalsIgnoreCase("set")) {
if(args[1].equalsIgnoreCase("enable-armorstand-restriction")){
if(args.length > 2) {
Main.getInstance().getConfig().set("enable-armorstand-restriction", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eenable-armorstand-restriction has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eenable-armorstand-restriction has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set enable-armorstand-restriction [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set enable-armorstand-restriction [§atrue§e/§cfalse§e]");
}
} else if(args[1].equalsIgnoreCase("allow-armorstand-only-in-plottype")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("allow-armorstand-only-in-plottype", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eallow-armorstand-only-in-plottype has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eallow-armorstand-only-in-plottype has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set allow-armorstand-only-in-plottype [§aARENA,BANK,COMMERCIAL,EMBASSY,FARM,INN,JAIL,RESIDENTIAL,WILDS§e]");
Main.log.info(Main.prefix + "§e/townytweaks set allow-armorstand-only-in-plottype [§aARENA,BANK,COMMERCIAL,EMBASSY,FARM,INN,JAIL,RESIDENTIAL,WILDS§e]");
}
} else if(args[1].equalsIgnoreCase("enable-shulker-restriction")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("enable-shulker-restriction", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eenable-shulker-restriction has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eenable-shulker-restriction has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set enable-shulker-restriction [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set enable-shulker-restriction [§atrue§e/§cfalse§e]");
}
} else if(args[1].equalsIgnoreCase("enable-brew-barrels-restriction")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("enable-brew-barrels-restriction", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eenable-brew-barrels-restriction has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eenable-brew-barrels-restriction has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set enable-brew-barrels-restriction [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set enable-brew-barrels-restriction [§atrue§e/§cfalse§e]");
}
} else if(args[1].equalsIgnoreCase("allow-barrels-only-in-plottype")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("allow-barrels-only-in-plottype", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eallow-barrels-only-in-plottype has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eallow-barrels-only-in-plottype has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set allow-barrels-only-in-plottype [§aARENA,BANK,COMMERCIAL,EMBASSY,FARM,INN,JAIL,RESIDENTIAL,WILDS§e]");
Main.log.info(Main.prefix + "§e/townytweaks set allow-barrels-only-in-plottype [§aARENA,BANK,COMMERCIAL,EMBASSY,FARM,INN,JAIL,RESIDENTIAL,WILDS§e]");
}
} else if(args[1].equalsIgnoreCase("keep-inventory-in-sieges")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("keep-inventory-in-sieges", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§ekeep-inventory-in-sieges has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§ekeep-inventory-in-sieges has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set keep-inventory-in-sieges [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set keep-inventory-in-sieges [§atrue§e/§cfalse§e]");
}
} else if(args[1].equalsIgnoreCase("allow-pearls-in-besieged-towns")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("allow-pearls-in-besieged-towns", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§eallow-pearls-in-besieged-towns has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§eallow-pearls-in-besieged-towns has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set allow-pearls-in-besieged-towns [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set allow-pearls-in-besieged-towns [§atrue§e/§cfalse§e]");
}
} else if(args[1].equalsIgnoreCase("spawn-trap-prevention-in-capitals")) {
if(args.length > 2) {
Main.getInstance().getConfig().set("spawn-trap-prevention-in-capitals", args[2].toLowerCase());
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§espawn-trap-prevention-in-capitals has been set to §b" + args[2].toLowerCase());
Main.log.info(Main.prefix + "§espawn-trap-prevention-in-capitals has been set to §b" + args[2].toLowerCase());
} else {
if(sender instanceof Player)
sender.sendMessage(Main.prefix + "§e/townytweaks set spawn-trap-prevention-in-capitals [§atrue§e/§cfalse§e]");
Main.log.info(Main.prefix + "§e/townytweaks set spawn-trap-prevention-in-capitals [§atrue§e/§cfalse§e]");
}
}

}
}
return false;
Expand Down
11 changes: 8 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
# You will find almost every feature that isn't in Towny here and you can always enable or disable it!
# If one of the features TownyTweaks offers ends up added to Towny, it is recommended that you turn the feature off in this config
# and configure the feature in the main Towny config file (/plugins/Towny/settings/)

# # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Required Towny version for this plugin: 0.98.2.0.
# Required Java version: 17.
# Required server type: Paper or any fork of Paper.
# Required Towny version for this plugin: 0.98.4.0. #
# Required Java version: 17. #
# Required server type: Paper or any fork of Paper. #
# Required Minecraft version: 1.18.2 or above. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # #

townytweaks-prefix: "§e[§bTownyTweaks§e]:§f "
# TownyTweaks ingame output prefix.

enable-armorstand-restriction: false
# Set to false to allow armor stand interaction anywhere, as long as the manipulator has permissions to the plot the stand is in.
# Set to true if you want the opposite, configure it below.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ commands:
townytweaks:
permission: townytweaks.admin
permission-message: You do not have permission to use this command.
usage: /townytweaks <reload> or /townytweaks <set> <option> <var>
usage: /townytweaks reload

0 comments on commit 8b20bf6

Please sign in to comment.