Commit 038e987b authored by Amosar's avatar Amosar

Spigot1.13

parent 9c84e448
......@@ -3,7 +3,8 @@ version: 0.10.4
description: Limit the redstoneClock
author: Amosar
website: https://www.spigotmc.org/resources/antiredstoneclock.18557
api-version: 1.13
main: com.trafalcraft.antiRedstoneClock.Main
commands:
......
......@@ -16,107 +16,100 @@ import org.yaml.snakeyaml.error.YAMLException;
import java.util.ArrayList;
import java.util.Collection;
public class Main extends JavaPlugin{
private static Main instance;
private static JavaPlugin plugin;
private static final ArrayList<String> ignoredWorlds = new ArrayList<>();
private static final ArrayList<String> ignoredRegions = new ArrayList<>();
public void onEnable(){
long startTime = System.currentTimeMillis();
instance = this;
plugin = this;
plugin.saveDefaultConfig();
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
plugin.reloadConfig();
try{
Msg.load();
}catch(YAMLException e){
e.printStackTrace();
}
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
try {
Material checked = Material.REDSTONE_COMPARATOR_OFF;
if (plugin.getConfig().getBoolean("checkedClock.comparator")) {
Bukkit.getServer().getPluginManager().registerEvents(new ComparatorListener(), this);
}
} catch (java.lang.NoSuchFieldError ignored) {
public class Main extends JavaPlugin {
private static Main instance;
//Store region and world ignored by the plugin
private static final ArrayList<String> ignoredWorlds = new ArrayList<>();
private static final ArrayList<String> ignoredRegions = new ArrayList<>();
public void onEnable() {
long startTime = System.currentTimeMillis();
instance = this;
instance.saveDefaultConfig();
instance.getConfig().options().copyDefaults(true);
instance.saveConfig();
instance.reloadConfig();
try {
Msg.load();
} catch (YAMLException e) {
e.printStackTrace();
}
//Register events depend on user preferences in config.yml file
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
if (instance.getConfig().getBoolean("checkedClock.comparator")) {
Bukkit.getServer().getPluginManager().registerEvents(new ComparatorListener(), this);
}
try {
Material checked = Material.OBSERVER;
if (instance.getConfig().getBoolean("checkedClock.observer")) {
Bukkit.getServer().getPluginManager().registerEvents(new ObserverListener(), this);
}
try {
Material checked = Material.OBSERVER;
if (plugin.getConfig().getBoolean("checkedClock.observer")) {
Bukkit.getServer().getPluginManager().registerEvents(new ObserverListener(), this);
}
} catch (java.lang.NoSuchFieldError ignored) {
}
if (plugin.getConfig().getBoolean("checkedClock.piston")) {
Bukkit.getServer().getPluginManager().registerEvents(new PistonListener(), this);
}
if (plugin.getConfig().getBoolean("checkedClock.redstoneAndRepeater")) {
Bukkit.getServer().getPluginManager().registerEvents(new RedstoneListener(), this);
}
long endTime = System.currentTimeMillis();
long duration = (endTime - startTime);
this.getLogger().info("Plugin loaded in "+duration+"ms"); //2ms
}
public void onDisable(){
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[]args){
if(cmd.getName().equalsIgnoreCase("antiredstoneclock")){
if(sender.isOp() || sender.hasPermission("antiRedstoneClock.Admin")){
if(args.length == 0){
Msg.getHelp(sender);
return false;
}
if(args[0].equalsIgnoreCase("Reload")){
Reload.getInstance().performCMD(sender);
} else if(args[0].equalsIgnoreCase("checkList")){
CheckList.getInstance().performCMD(sender, args);
}else if(args[0].equalsIgnoreCase("setMaxPulses")){
SetMaxPulses.getInstance().performCMD(sender, args);
}else if(args[0].equalsIgnoreCase("SetDelay")){
SetDelay.getInstance().performCMD(sender, args);
}else if(args[0].equalsIgnoreCase("NotifyAdmin")){
NotifyAdmin.getInstance().performCMD(sender, args);
} catch (java.lang.NoSuchFieldError ignored) {
}
if (instance.getConfig().getBoolean("checkedClock.piston")) {
Bukkit.getServer().getPluginManager().registerEvents(new PistonListener(), this);
}
if (instance.getConfig().getBoolean("checkedClock.redstoneAndRepeater")) {
Bukkit.getServer().getPluginManager().registerEvents(new RedstoneListener(), this);
}
long endTime = System.currentTimeMillis();
long duration = (endTime - startTime);
this.getLogger().info("Plugin loaded in " + duration + "ms"); //2ms
}
public void onDisable() {
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("antiredstoneclock")) {
if (sender.isOp() || sender.hasPermission("antiRedstoneClock.Admin")) {
if (args.length == 0) {
Msg.getHelp(sender);
return false;
}
if (args[0].equalsIgnoreCase("Reload")) {
Reload.getInstance().performCMD(sender);
} else if (args[0].equalsIgnoreCase("checkList")) {
CheckList.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("setMaxPulses")) {
SetMaxPulses.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("SetDelay")) {
SetDelay.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("NotifyAdmin")) {
NotifyAdmin.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("AutoRemoveDetectedClock")) {
AutoRemoveDetectedClock.getInstance().performCMD(sender, args);
AutoRemoveDetectedClock.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("CreateSignWhenClockIsBreak")) {
CreateSignWhenClockIsBreak.getInstance().performCMD(sender, args);
CreateSignWhenClockIsBreak.getInstance().performCMD(sender, args);
} else {
Msg.getHelp(sender);
Msg.getHelp(sender);
}
}else{
sender.sendMessage(Msg.unknownCmd.toString());
}
}else{
sender.sendMessage(Msg.unknownCmd.toString());
}
return false;
}
public static Main getInstance(){
return instance;
}
public static JavaPlugin getPlugin(){
return plugin;
}
public static Collection<String> getIgnoredWorlds(){
return ignoredWorlds;
}
public static Collection<String> getIgnoredRegions(){
return ignoredRegions;
}
} else {
sender.sendMessage(Msg.UNKNOWN_CMD.toString());
}
} else {
sender.sendMessage(Msg.UNKNOWN_CMD.toString());
}
return false;
}
public static Main getInstance() {
return instance;
}
public static Collection<String> getIgnoredWorlds() {
return ignoredWorlds;
}
public static Collection<String> getIgnoredRegions() {
return ignoredRegions;
}
}
\ No newline at end of file
......@@ -12,62 +12,71 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
public class PlayerListener implements Listener {
@EventHandler (priority = EventPriority.HIGHEST)
public void onPlayerBreakRedstone(BlockBreakEvent e) {
try{
if (e.getBlock().getType() == Material.REDSTONE_WIRE
|| e.getBlock().getType() == Material.DIODE_BLOCK_ON
|| e.getBlock().getType() == Material.DIODE_BLOCK_OFF
|| e.getBlock().getType() == Material.PISTON_BASE
|| e.getBlock().getType() == Material.PISTON_EXTENSION
|| e.getBlock().getType() == Material.PISTON_MOVING_PIECE
|| e.getBlock().getType() == Material.PISTON_STICKY_BASE
|| e.getBlock().getType() == Material.REDSTONE_COMPARATOR
|| e.getBlock().getType() == Material.REDSTONE_COMPARATOR_OFF
|| e.getBlock().getType() == Material.REDSTONE_COMPARATOR_ON
|| e.getBlock().getType() == Material.OBSERVER) {
if (RedstoneClockController.contains(e.getBlock().getLocation())) {
RedstoneClockController.removeRedstoneByLocation(e.getBlock().getLocation());
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerBreakRedstone(BlockBreakEvent e) {
if (checkRedStoneItems_1_13(e.getBlock().getType())
|| checkRedStoneItemsOlderThan_1_13(e.getBlock().getType())) {
if (RedstoneClockController.contains(e.getBlock().getLocation())) {
RedstoneClockController.removeRedstoneByLocation(e.getBlock().getLocation());
}
}catch(java.lang.NoSuchFieldError ignored){}
if (e.getBlock().getType() == Material.SIGN || e.getBlock().getType() == Material.SIGN_POST) {
BlockState block = e.getBlock().getState();
Sign sign = (Sign) block;
if (sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))) {
} else if (e.getBlock().getType() == Material.getMaterial("SIGN")
|| e.getBlock().getType() == Material.getMaterial("SIGN_POST")) {
BlockState blockState = e.getBlock().getState();
Sign sign = (Sign) blockState;
if (sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
}
@EventHandler (priority = EventPriority.HIGHEST)
public void onItemDrop(BlockPhysicsEvent e){
if (e.getBlock().getType() == Material.SIGN || e.getBlock().getType() == Material.SIGN_POST) {
BlockState block = e.getBlock().getState();
Sign sign = (Sign) block;
if ((sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))
&& e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR)) {
}
}
private boolean checkRedStoneItems_1_13(Material type) {
return type == Material.getMaterial("REDSTONE_WIRE")
|| type == Material.getMaterial("REPEATER")
|| type == Material.getMaterial("PISTON")
|| type == Material.getMaterial("STICKY_PISTON")
|| type == Material.getMaterial("COMPARATOR")
|| type == Material.getMaterial("OBSERVER");
}
private boolean checkRedStoneItemsOlderThan_1_13(Material type) {
return type == Material.getMaterial("DIODE_BLOCK_OFF")
|| type == Material.getMaterial("DIODE_BLOCK_ON")
|| type == Material.getMaterial("PISTON_BASE")
|| type == Material.getMaterial("PISTON_EXTENSION")
|| type == Material.getMaterial("PISTON_STICKY_BASE")
|| type == Material.getMaterial("REDSTONE_COMPARATOR_OFF")
|| type == Material.getMaterial("REDSTONE_COMPARATOR_ON");
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDrop(BlockPhysicsEvent e) {
if (e.getBlock().getType() == Material.getMaterial("SIGN")
|| e.getBlock().getType() == Material.getMaterial("SIGN_POST")) {
BlockState block = e.getBlock().getState();
Sign sign = (Sign) block;
if ((sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))
&& e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR)) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
}
}
}
}
......@@ -3,46 +3,37 @@ package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
public class AutoRemoveDetectedClock {
private static AutoRemoveDetectedClock ourInstance = new AutoRemoveDetectedClock();
private static final AutoRemoveDetectedClock ourInstance = new AutoRemoveDetectedClock();
public static AutoRemoveDetectedClock getInstance() {
return ourInstance;
}
public static AutoRemoveDetectedClock getInstance() {
return ourInstance;
}
private AutoRemoveDetectedClock() {
}
private AutoRemoveDetectedClock() {
}
public void performCMD(CommandSender sender, String... args) {
if (args.length == 1) {
if (Main.getInstance().getConfig().getBoolean("AutomaticallyBreakDetectedClock")) {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", "false"));
} else {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", "true"));
}
} else {
if (Boolean.parseBoolean(args[1])) {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", args[1]));
} else if (!Boolean.parseBoolean(args[1])) {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", args[1]));
}
}
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("AutomaticallyBreakDetectedClock"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "AutomaticallyBreakDetectedClock <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("AutomaticallyBreakDetectedClock", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", String.valueOf(newValue)));
}
}
......@@ -6,8 +6,10 @@ import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import java.util.Collection;
public class CheckList {
private static CheckList ourInstance = new CheckList();
private static final CheckList ourInstance = new CheckList();
public static CheckList getInstance() {
return ourInstance;
......@@ -16,46 +18,43 @@ public class CheckList {
private CheckList() {
}
public void performCMD(CommandSender sender, String... args){
try{
int test = 5;
if(args.length > 1){
test = Integer.parseInt(args[1]) * 5;
public void performCMD(CommandSender sender, String... args) {
try {
int page = 1;
if (args.length > 1) {
page = Integer.parseInt(args[1]);
}
int i = 0;
sender.sendMessage(Msg.RedStoneClockListHeader.toString().replace("$page",
"(" + test / 5 + "/" + ((RedstoneClockController.getAllLoc().size() / 5) + 1) + ")"));
for(Location loc : RedstoneClockController.getAllLoc()){
if(!(i+1 > test+1) && !(i+1 < test-4)){
Collection<Location> allLocation = RedstoneClockController.getAllLoc();
int totalPage = (int) Math.ceil(allLocation.size() / 5.0);
sender.sendMessage(Msg.RED_STONE_CLOCK_LIST_HEADER.toString().replace("$page",
"(" + page + "/" + totalPage + ")"));
int i = 1;
int minElements = 5 * (page - 1);
int maxElements = 5 * page;
for (Location loc : allLocation) {
if (i > minElements && i <= maxElements) {
int maxPulses = Main.getInstance().getConfig().getInt("MaxPulses");
int clock = RedstoneClockController.getRedstoneClock(loc).getNumberOfClock();
String color = "§2"; //Dark_Green
if (clock > maxPulses * 0.75) {
sender.sendMessage(
"§4RedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
color = "§4"; //Dark_Red
} else if (clock > maxPulses * 0.5) {
sender.sendMessage(
"§eRedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
color = "§e"; //yellow
} else if (clock > maxPulses * 0.250) {
sender.sendMessage(
"§aRedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
}else{
sender.sendMessage(
"§2RedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
color = "§a"; // green
}
sender.sendMessage(color + "RedStoneClock> §fWorld:" + loc.getWorld().getName()
+ ",X:" + loc.getX()
+ ",Y:" + loc.getY()
+ ",Z:" + loc.getZ()
+ " b:" + clock + "/" + maxPulses);
}
i++;
}
sender.sendMessage(Msg.RedStoneClockListFooter.toString());
}catch(NumberFormatException e){
sender.sendMessage(Msg.Command_Use.toString().replace("$command", "checkList <number>"));
sender.sendMessage(Msg.RED_STONE_CLOCK_LIST_FOOTER.toString());
} catch (NumberFormatException e) {
sender.sendMessage(Msg.COMMAND_USE.toString().replace("$command", "checkList <number>"));
}
}
}
......@@ -3,46 +3,37 @@ package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
public class CreateSignWhenClockIsBreak {
private static CreateSignWhenClockIsBreak ourInstance = new CreateSignWhenClockIsBreak();
private static final CreateSignWhenClockIsBreak ourInstance = new CreateSignWhenClockIsBreak();
public static CreateSignWhenClockIsBreak getInstance() {
return ourInstance;
}
public static CreateSignWhenClockIsBreak getInstance() {
return ourInstance;
}
private CreateSignWhenClockIsBreak() {
}
private CreateSignWhenClockIsBreak() {
}
public void performCMD(CommandSender sender, String... args) {
if (args.length == 1) {
if (Main.getInstance().getConfig().getBoolean("CreateSignWhenClockIsBreak")) {
Main.getInstance().getConfig().set("CreateSignWhenClockIsBreak", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", "false"));
} else {
Main.getInstance().getConfig().set("CreateSignWhenClockIsBreak", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", "true"));
}
} else {
if (Boolean.parseBoolean(args[1])) {
Main.getInstance().getConfig().set("CreateSignWhenClockIsBreak", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", args[1]));
} else if (!Boolean.parseBoolean(args[1])) {
Main.getInstance().getConfig().set("CreateSignWhenClockIsBreak", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", args[1]));
}
}
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("CreateSignWhenClockIsBreak"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "CreateSignWhenClockIsBreak <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("CreateSignWhenClockIsBreak", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"CreateSignWhenClockIsBreak\"")
.replace("$value", String.valueOf(newValue)));
}
}
......@@ -3,9 +3,10 @@ package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
public class NotifyAdmin {
private static NotifyAdmin ourInstance = new NotifyAdmin();
private static final NotifyAdmin ourInstance = new NotifyAdmin();
public static NotifyAdmin getInstance() {
return ourInstance;
......@@ -14,31 +15,25 @@ public class NotifyAdmin {
private NotifyAdmin() {
}
public void performCMD(CommandSender sender, String... args){
if(args.length == 1){
if(Main.getInstance().getConfig().getBoolean("NotifyAdmins")){
Main.getInstance().getConfig().set("NotifyAdmins", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", "false"));
}else{
Main.getInstance().getConfig().set("NotifyAdmins", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", "true"));
}
}else{
if(Boolean.parseBoolean(args[1])){
Main.getInstance().getConfig().set("NotifyAdmins", true);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", args[1]));
}else if(!Boolean.parseBoolean(args[1])){
Main.getInstance().getConfig().set("NotifyAdmins", false);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", args[1]));
public void performCMD(CommandSender sender, String... args) {
FileConfiguration config = Main.getInstance().getConfig();
if (args.length == 1) {
changeValueAndSendMessage(sender, config, !config.getBoolean("NotifyAdmins"));
} else {
if (args[1].equalsIgnoreCase("true")) {
changeValueAndSendMessage(sender, config, true);
} else if (!args[1].equalsIgnoreCase("false")) {
sender.sendMessage(Msg.COMMAND_USE.toString()
.replace("$command", "NotifyAdmins <true/false>"));
}
}
}
private void changeValueAndSendMessage(CommandSender sender, FileConfiguration config, boolean newValue) {
config.set("NotifyAdmins", newValue);
Main.getInstance().saveConfig();
sender.sendMessage(Msg.PREFIX + Msg.NEW_VALUE_IN_CONFIG.toString()
.replace("$setting", "\"NotifyAdmins\"")
.replace("$value", String.valueOf(newValue)));
}
}
......@@ -7,7 +7,7 @@ import org.bukkit.entity.Player;
import org.yaml.snakeyaml.error.YAMLException;
public class Reload {
private static Reload ourInstance = new Reload();
private static final Reload ourInstance = new Reload();
public static Reload getInstance() {
return ourInstance;
......@@ -16,18 +16,18 @@ public class Reload {
private Reload() {
}