Commit f2824bc5 authored by Amosar's avatar Amosar

Push All classes (Error on the last commit)

-Correct sign duplication error (Again)
-Improve Configuration management
-add setting to disable the signs
Signed-off-by: Amosar's avatarAmosar <maxi.cass11@gmail.com>
parent 0cd770e6
......@@ -13,6 +13,8 @@ NotifyAdmins: true
#En:Is it necessary to dropper items ( Redstone / repeater) when a loop is destroyed?
#Fr:Faut-il dropper les items (Redstone/repeater) quand une boucle est détruite?
DropItems: true
CreateSignWhenClockIsBreak: true
#En:Write the text you want in the sign
#Fr:Ecrire le texte a mettre sur les panneaux
Sign:
......
name: antiRedstoneClock
version: 0.10.2
version: 0.10.3
description: Limit the redstoneClock
author: Amosar
website: https://www.spigotmc.org/resources/antiredstoneclock.18557
......
......@@ -5,9 +5,7 @@ import com.trafalcraft.antiRedstoneClock.listener.ComparatorListener;
import com.trafalcraft.antiRedstoneClock.listener.ObserverListener;
import com.trafalcraft.antiRedstoneClock.listener.PistonListener;
import com.trafalcraft.antiRedstoneClock.listener.RedstoneListener;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClock;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClockController;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
......@@ -15,7 +13,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import org.yaml.snakeyaml.error.YAMLException;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
......@@ -23,15 +20,6 @@ public class Main extends JavaPlugin{
private static Main instance;
private static JavaPlugin plugin;
private int maximumPulses;
private int delay;
private boolean notifyAdmin;
private boolean DropItems;
private boolean automaticallyBreakDetectedClock;
private String line1;
private String line2;
private String line3;
private String line4;
private static final ArrayList<String> ignoredWorlds = new ArrayList<>();
private static final ArrayList<String> ignoredRegions = new ArrayList<>();
......@@ -42,23 +30,14 @@ public class Main extends JavaPlugin{
instance = this;
plugin = this;
plugin.getConfig().options().copyDefaults(true);
plugin.saveDefaultConfig();
plugin.reloadConfig();
if (!getConfig().getString("version").equals("0.6")) {
File f = new File(getPlugin().getDataFolder().getPath() + "//config.yml");
File newFile = new File(f.getPath() + "-" + getConfig().getString("version") + ".old");
f.renameTo(newFile);
plugin.getConfig().options().copyDefaults(true);
plugin.saveDefaultConfig();
plugin.reloadConfig();
}
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
plugin.reloadConfig();
try{
CustomConfig.load();
Msg.load();
}catch(YAMLException e){
CustomConfig.setDefaultsValues();
e.printStackTrace();
}
......@@ -83,29 +62,12 @@ public class Main extends JavaPlugin{
if (plugin.getConfig().getBoolean("checkedClock.redstoneAndRepeater")) {
Bukkit.getServer().getPluginManager().registerEvents(new RedstoneListener(), this);
}
if (!plugin.getConfig().contains("AutomaticallyBreakDetectedClock")) {
plugin.getConfig().set("AutomaticallyBreakDetectedClock", true);
automaticallyBreakDetectedClock = true;
plugin.saveConfig();
}
checkTimer(getDelay());
long endTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis();
long duration = (endTime - startTime);
this.getLogger().info("Plugin loaded in "+duration+"ms"); //2ms
}
private static void checkTimer(int delay){
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, () -> {
for(RedstoneClock rdc : RedstoneClockController.getAll()){
if(rdc.isEnd()){
RedstoneClockController.removeRedstoneByObject(rdc);
}
}
}, 100, 20 * delay);
}
public void onDisable(){
}
......@@ -113,7 +75,7 @@ public class Main extends JavaPlugin{
if(cmd.getName().equalsIgnoreCase("antiredstoneclock")){
if(sender.isOp() || sender.hasPermission("antiRedstoneClock.Admin")){
if(args.length == 0){
CustomConfig.getHelp(sender);
Msg.getHelp(sender);
return false;
}
if(args[0].equalsIgnoreCase("Reload")){
......@@ -128,14 +90,16 @@ public class Main extends JavaPlugin{
NotifyAdmin.getInstance().performCMD(sender, args);
} else if (args[0].equalsIgnoreCase("AutoRemoveDetectedClock")) {
AutoRemoveDetectedClock.getInstance().performCMD(sender, args);
}else{
CustomConfig.getHelp(sender);
}
} else if (args[0].equalsIgnoreCase("CreateSignWhenClockIsBreak")) {
CreateSignWhenClockIsBreak.getInstance().performCMD(sender, args);
} else {
Msg.getHelp(sender);
}
}else{
sender.sendMessage(CustomConfig.unknownCmd.toString());
sender.sendMessage(Msg.unknownCmd.toString());
}
}else{
sender.sendMessage(CustomConfig.unknownCmd.toString());
sender.sendMessage(Msg.unknownCmd.toString());
}
return false;
}
......@@ -148,74 +112,6 @@ public class Main extends JavaPlugin{
return plugin;
}
public static int getMaximumPulses(){
return instance.maximumPulses;
}
public static void setMaximumPulses(int value){
instance.maximumPulses = value;
}
public static int getDelay(){
return instance.delay;
}
public static void setDelay(int delay){
instance.delay = delay;
}
public static boolean isNotifyAdmin(){
return instance.notifyAdmin;
}
public static void setNotifyAdmin(boolean value ){
instance.notifyAdmin = value;
}
public static boolean isDropItems() {
return instance.DropItems;
}
public static void setDropItems(boolean dropItems) {
instance.DropItems = dropItems;
}
public static boolean automaticallyDropDetectedItem() {
return instance.automaticallyBreakDetectedClock;
}
public static void setAutomaticallyDropDetectedItem(boolean automaticallyBreakDetectedClock) {
instance.automaticallyBreakDetectedClock = automaticallyBreakDetectedClock;
}
public static String getLine1(){
return instance.line1;
}
public static void setLine1(String value){
instance.line1 = value;
}
public static String getLine2(){
return instance.line2;
}
public static void setLine2(String value){
instance.line2 = value;
}
public static String getLine3(){
return instance.line3;
}
public static void setLine3(String value){
instance.line3 = value;
}
public static String getLine4(){
return instance.line4;
}
public static void setLine4(String value){
instance.line4 = value;
}
public static Collection<String> getIgnoredWorlds(){
return ignoredWorlds;
}
......
......@@ -35,10 +35,14 @@ public class PlayerListener implements Listener {
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.getLine1())
&& sign.getLine(1).equalsIgnoreCase(Main.getLine2())
&& sign.getLine(2).equalsIgnoreCase(Main.getLine3())
&& sign.getLine(3).equalsIgnoreCase(Main.getLine4())) {
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);
......@@ -51,10 +55,14 @@ public class PlayerListener implements Listener {
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.getLine1())
&& sign.getLine(1).equalsIgnoreCase(Main.getLine2())
&& sign.getLine(2).equalsIgnoreCase(Main.getLine3())
&& sign.getLine(3).equalsIgnoreCase(Main.getLine4())
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);
......
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
public class AutoRemoveDetectedClock {
......@@ -18,32 +18,28 @@ public class AutoRemoveDetectedClock {
if (args.length == 1) {
if (Main.getInstance().getConfig().getBoolean("AutomaticallyBreakDetectedClock")) {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", false);
Main.setAutomaticallyDropDetectedItem(false);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix + CustomConfig.newValueInConfig.toString()
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", "false"));
} else {
Main.getInstance().getConfig().set("AutomaticallyBreakDetectedClock", true);
Main.setAutomaticallyDropDetectedItem(true);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix + CustomConfig.newValueInConfig.toString()
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.setAutomaticallyDropDetectedItem(true);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix + CustomConfig.newValueInConfig.toString()
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.setAutomaticallyDropDetectedItem(false);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix + CustomConfig.newValueInConfig.toString()
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString()
.replace("$setting", "\"AutomaticallyBreakDetectedClock\"")
.replace("$value", args[1]));
}
......
......@@ -2,7 +2,7 @@ package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClockController;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
......@@ -23,24 +23,39 @@ public class CheckList {
test = Integer.parseInt(args[1]) * 5;
}
int i = 0;
sender.sendMessage(CustomConfig.RedStoneClockListHeader.toString().replace("$page", "("+test/5+"/"+((RedstoneClockController.getAllLoc().size()/5)+1)+")"));
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)){
if(RedstoneClockController.getRedstoneClock(loc).getClock() > Main.getMaximumPulses()*0.750){
sender.sendMessage("§4RedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getClock()+"/"+Main.getMaximumPulses());
}else if (RedstoneClockController.getRedstoneClock(loc).getClock() > Main.getMaximumPulses()*0.5){
sender.sendMessage("§eRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getClock()+"/"+Main.getMaximumPulses());
}else if (RedstoneClockController.getRedstoneClock(loc).getClock() > Main.getMaximumPulses()*0.250){
sender.sendMessage("§aRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getClock()+"/"+Main.getMaximumPulses());
int maxPulses = Main.getInstance().getConfig().getInt("MaxPulses");
int clock = RedstoneClockController.getRedstoneClock(loc).getNumberOfClock();
if (clock > maxPulses * 0.75) {
sender.sendMessage(
"§4RedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
} 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);
} 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:"+RedstoneClockController.getRedstoneClock(loc).getClock()+"/"+Main.getMaximumPulses());
sender.sendMessage(
"§2RedStoneClock> §fWorld:" + loc.getWorld().getName() + ",X:" + loc.getX() + ",Y:"
+ loc.getY() + ",Z:" + loc.getZ() + " b:" + clock
+ "/" + maxPulses);
}
}
i++;
}
sender.sendMessage(CustomConfig.RedStoneClockListFooter.toString());
sender.sendMessage(Msg.RedStoneClockListFooter.toString());
}catch(NumberFormatException e){
sender.sendMessage(CustomConfig.Command_Use.toString().replace("$command", "checkList <number>"));
sender.sendMessage(Msg.Command_Use.toString().replace("$command", "checkList <number>"));
}
}
}
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
public class CreateSignWhenClockIsBreak {
private static CreateSignWhenClockIsBreak ourInstance = new CreateSignWhenClockIsBreak();
public static CreateSignWhenClockIsBreak getInstance() {
return ourInstance;
}
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]));
}
}
}
}
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
public class NotifyAdmin {
......@@ -18,26 +18,26 @@ public class NotifyAdmin {
if(args.length == 1){
if(Main.getInstance().getConfig().getBoolean("NotifyAdmins")){
Main.getInstance().getConfig().set("NotifyAdmins", false);
Main.setNotifyAdmin(false);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"").replace("$value", "false"));
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", "false"));
}else{
Main.getInstance().getConfig().set("NotifyAdmins", true);
Main.setNotifyAdmin(true);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"").replace("$value", "true"));
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.setNotifyAdmin(true);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"").replace("$value", args[1]));
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.setNotifyAdmin(false);
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"").replace("$value", args[1]));
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"")
.replace("$value", args[1]));
}
}
}
......
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.yaml.snakeyaml.error.YAMLException;
......@@ -21,11 +21,11 @@ public class Reload {
Main.getPlugin().reloadConfig();
Main.getIgnoredWorlds().clear();
Main.getIgnoredRegions().clear();
CustomConfig.load();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.reloadSuccess.toString());
Msg.load();
sender.sendMessage(Msg.Prefix + Msg.reloadSuccess.toString());
}catch(YAMLException e){
if(sender instanceof Player){
sender.sendMessage(CustomConfig.ERROR +"An error as occurred in the config.yml please check the log!");
sender.sendMessage(Msg.ERROR + "An error as occurred in the config.yml please check the log!");
}
Main.getInstance().getLogger().severe("An error as occurred in the config.yml please fix it!");
e.printStackTrace();
......
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
public class SetDelay {
......@@ -16,12 +16,13 @@ public class SetDelay {
public void performCMD(CommandSender sender, String... args){
try{
Main.setDelay(Integer.parseInt(args[1]));
Main.getInstance().getConfig().set("Delay", Main.getDelay());
Main.getInstance().getConfig().set("Delay", Integer.parseInt(args[1]));
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"Delay\"").replace("$value", args[1]));
sender.sendMessage(
Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"Delay\"")
.replace("$value", args[1]));
}catch(NumberFormatException e){
sender.sendMessage(CustomConfig.Command_Use.toString().replace("$command", "SetDelay <number>"));
sender.sendMessage(Msg.Command_Use.toString().replace("$command", "SetDelay <number>"));
}
}
}
package com.trafalcraft.antiRedstoneClock.commands;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import org.bukkit.command.CommandSender;
public class SetMaxPulses {
......@@ -16,12 +16,12 @@ public class SetMaxPulses {
public void performCMD(CommandSender sender, String... args){
try{
Main.setMaximumPulses(Integer.parseInt(args[1]));
Main.getInstance().getConfig().set("MaxPulses", Main.getMaximumPulses());
Main.getInstance().getConfig().set("MaxPulses", Integer.parseInt(args[1]));
Main.getInstance().saveConfig();
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"MaxPulses\"").replace("$value", args[1]));
sender.sendMessage(Msg.Prefix + Msg.newValueInConfig.toString().replace("$setting", "\"MaxPulses\"")
.replace("$value", args[1]));
}catch(NumberFormatException e){
sender.sendMessage(CustomConfig.Command_Use.toString().replace("$command", "setMaxPulses <number>"));
sender.sendMessage(Msg.Command_Use.toString().replace("$command", "setMaxPulses <number>"));
}
}
}
......@@ -34,7 +34,8 @@ public class ComparatorListener implements Listener{
if(redstoneClock.getLastStatus() != status){
if(status == 0) {
if (!redstoneClock.isEnd()) {
if (redstoneClock.getClock() >= Main.getMaximumPulses()) {
if (redstoneClock.getNumberOfClock()
>= Main.getInstance().getConfig().getInt("MaxPulses")) {
Util.removeRedstoneClock(e.getBlock());
} else {
redstoneClock.addOneToClock();
......
......@@ -17,7 +17,7 @@ public class PistonListener implements Listener {
RedstoneClock redstoneClock = RedstoneClockController.getRedstoneClock(e.getBlock().getLocation());
if(redstoneClock.getLastStatus() == 1 ) {
if (!redstoneClock.isEnd()) {
if (redstoneClock.getClock() >= Main.getMaximumPulses()) {
if (redstoneClock.getNumberOfClock() >= Main.getInstance().getConfig().getInt("MaxPulses")) {
Util.removeRedstoneClock(e.getBlock());
} else {
redstoneClock.addOneToClock();
......
......@@ -32,7 +32,7 @@ public class RedstoneListener implements Listener{
RedstoneClock redstoneClock = RedstoneClockController.getRedstoneClock(e.getBlock().getLocation());
if(!redstoneClock.isEnd()){
if(redstoneClock.getClock() >= Main.getMaximumPulses()){
if (redstoneClock.getNumberOfClock() >= Main.getInstance().getConfig().getInt("MaxPulses")) {
Util.removeRedstoneClock(e.getBlock());
}else{
redstoneClock.addOneToClock();
......
......@@ -3,7 +3,7 @@ package com.trafalcraft.antiRedstoneClock.listener;
import com.trafalcraft.antiRedstoneClock.Main;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClock;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClockController;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.Msg;
import com.trafalcraft.antiRedstoneClock.util.WorldGuardLink;
import org.bukkit.Bukkit;
import org.bukkit.Material;
......@@ -22,8 +22,8 @@ class Util {
}
}else{
if (!RedstoneClockController.getRedstoneClock(block.getLocation()).isEnd()) {
if (RedstoneClockController.getRedstoneClock(block.getLocation()).getClock() >= Main
.getMaximumPulses()) {
if (RedstoneClockController.getRedstoneClock(block.getLocation()).getNumberOfClock()
>= Main.getInstance().getConfig().getInt("MaxPulses")) {
removeRedstoneClock(block);
}else{
RedstoneClockController.getRedstoneClock(block.getLocation()).addOneToClock();
......@@ -41,32 +41,38 @@ class Util {
return WorldGuardLink.checkAllowedRegion(block.getLocation());
}
static synchronized void removeRedstoneClock(Block block) {
if (Main.automaticallyDropDetectedItem()) {
if (Main.isDropItems()) {
static void removeRedstoneClock(Block block) {
if (Main.getInstance().getConfig().getBoolean("AutomaticallyBreakDetectedClock")) {
if (Main.getInstance().getConfig().getBoolean("DropItems")) {
block.breakNaturally();
} else {
block.setType(Material.AIR);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
block.setType(Material.SIGN_POST);
BlockState blockState = block.getState();
Sign sign = (Sign) blockState;
sign.setLine(0, Main.getLine1());
sign.setLine(1, Main.getLine2());
sign.setLine(2, Main.getLine3());
sign.setLine(3, Main.getLine4());
sign.update(false, false);
if (Main.getInstance().getConfig().getBoolean("CreateSignWhenClockIsBreak")) {
block.setType(Material.SIGN_POST, false);
BlockState blockState = block.getState();
Sign sign = (Sign) blockState;
sign.setLine(0, Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"));
sign.setLine(1, Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"));
sign.setLine(2, Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"));
sign.setLine(3, Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"));
sign.update(false, false);
}
Bukkit.getLogger()
.info(CustomConfig.Prefix + CustomConfig.MsgToAdmin.toString()
.info(Msg.Prefix + Msg.MsgToAdmin.toString()
.replace("$X", block.getX() + "")
.replace("$Y", block.getY() + "").replace("$Z", block.getZ() + "")
.replace("$World", block.getWorld().getName()));
if (Main.isNotifyAdmin()) {
if (Main.getInstance().getConfig().getBoolean("NotifyAdmins")) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.isOp() || p.hasPermission("antiRedstoneClock.NotifyAdmin")) {
p.sendMessage(
CustomConfig.Prefix + CustomConfig.MsgToAdmin.toString()
Msg.Prefix + Msg.MsgToAdmin.toString()
.replace("$X", block.getX() + "")
.replace("$Y", block.getY() + "")
.replace("$Z", block.getZ() + "")
......@@ -81,15 +87,16 @@ class Util {
if (!redstoneClock.getDetected()) {
redstoneClock.setDetected(true);
Bukkit.getLogger()
.info(CustomConfig.Prefix + CustomConfig.MsgToAdmin.toString()
.info(Msg.Prefix + Msg.MsgToAdmin.toString()
.replace("$X", block.getX() + "")
.replace("$Y", block.getY() + "").replace("$Z", block.getZ() + "")
.replace("$Y", block.getY() + "")
.replace("$Z", block.getZ() + "")
.replace("$World", block.getWorld().getName()));
if (Main.isNotifyAdmin()) {
if (Main.getInstance().getConfig().getBoolean("NotifyAdmins")) {
for (Player p : Bukkit.getOnlinePlayers()) {
if (p.isOp() || p.hasPermission("antiRedstoneClock.NotifyAdmin")) {
p.sendMessage(
CustomConfig.Prefix + CustomConfig.MsgToAdmin.toString()
Msg.Prefix + Msg.MsgToAdmin.toString()
.replace("$X", block.getX() + "")
.replace("$Y", block.getY() + "")
.replace("$Z", block.getZ() + "")
......