Commit 4e3cbd34 authored by Amosar's avatar Amosar

timer Fonctionnel+amelioration des detections/destruction des boucles

parent f0979a3d
#En:Don't touch this value
#Fr: Ne pas modifier cette valeur
version: 0.3
version: 0.4
#En:Maximal number Redstone blink authorized during the "Delay" period
#Fr:Nombre maximal de clignotement de redstone autorise pendant la periode "Delay"
MaxImpulsion: 150
......@@ -8,8 +8,11 @@ MaxImpulsion: 150
#Fr:Temp (en secondes) avant de reset la premiere variable
Delay: 300
#En:You need it prevent an admin?
#Fr:Faut t'il prevenir un admin?
#Fr:Faut-il prevenir un admin?
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
#En:Write the text you want in the sign
#Fr:Ecrire le texte a mettre sur les panneaux
Sign:
......@@ -24,7 +27,7 @@ IgnoreWorlds: redstoneWorld/survie
#En:The list of Region on which the plugin is disabled separate by "/", put a fake name if nothing
#Fr: La list des Regions sur lequel le plugin est desactive separe par des "/", mettre un faut non si aucun
IgnoreRegion: redstone/admins
IgnoreRegions: redstone/admins
Msg:
default:
......
name: antiRedstoneClock
version: 0.5
version: 0.6
description: Limit the redstoneClock
author: Amosar
......
......@@ -17,12 +17,12 @@ import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
public class Main extends JavaPlugin{
private RedstoneClockController rdc;
private static Main instance;
private static JavaPlugin plugin;
private int maxImpulsions;
private int delay;
private boolean notifyAdmin;
private boolean DropItems;
private String line1;
private String line2;
private String line3;
......@@ -36,17 +36,15 @@ public class Main extends JavaPlugin{
instance = this;
plugin = this;
this.rdc = new RedstoneClockController();
Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
checkTimer();
plugin.getConfig().options().copyDefaults(true);
plugin.saveDefaultConfig();
plugin.reloadConfig();
if(!getConfig().getString("version").equals("0.3")){
if(!getConfig().getString("version").equals("0.4")){
if(getConfig().getString("version").equals("0.1")){
System.out.println("update config file to 0.3");
System.out.println("update config file to 0.2");
getConfig().set("version", "0.2");
getConfig().set("IgnoreWorlds", "redstoneWorld/survival");
getConfig().set("IgnoreRegions", "redstone/admins");
......@@ -55,7 +53,8 @@ public class Main extends JavaPlugin{
getConfig().set("Msg.message.RedStoneClockListFooter", "");
plugin.saveConfig();
plugin.reloadConfig();
}if(getConfig().getString("version").equals("0.2")){
}
if(getConfig().getString("version").equals("0.2")){
System.out.println("update config file to 0.3");
getConfig().set("version", "0.3");
getConfig().set("IgnoreRegions", "redstone/admins");
......@@ -65,6 +64,13 @@ public class Main extends JavaPlugin{
plugin.saveConfig();
plugin.reloadConfig();
}
if(getConfig().getString("version").equals("0.3")){
System.out.println("update config file to 0.4");
getConfig().set("version", "0.4");
getConfig().set("DropItems", true);
plugin.saveConfig();
plugin.reloadConfig();
}
}
//if(instance.getConfig().getInt("version") != 0.1){
......@@ -102,6 +108,7 @@ public class Main extends JavaPlugin{
e.printStackTrace();
}
checkTimer(getDelay());
long endTime = System.currentTimeMillis();
long duration = (endTime - startTime);
......@@ -109,18 +116,18 @@ public class Main extends JavaPlugin{
this.getLogger().info("Plugin chargé en "+duration+"ms"); //2ms
}
private void checkTimer(){
private static void checkTimer(int delay){
Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, new Runnable() {
@Override
public void run() {
for(RedstoneClock brdc : getRDC().getAll()){
if(brdc.getMinutes() > brdc.getEndTimerInMinutes()){
getRDC().removeRedstoneByObject(brdc);
for(RedstoneClock brdc : RedstoneClockController.getAll()){
if(brdc.isEnd()){
RedstoneClockController.removeRedstoneByObject(brdc);
}
}
}
}, 0, 20*Main.getDelay());
}, 100, 20*delay);
}
public void onDisable(){
......@@ -131,6 +138,10 @@ public class Main extends JavaPlugin{
//Player p = (Player) sender;
if(cmd.getName().equalsIgnoreCase("antiredstoneclock")){
if(sender.isOp() || sender.hasPermission("antiRedstoneClock.Admin")){
if(args.length == 0){
CustomConfig.getHelp((Player) sender);
return false;
}
if(args[0].equalsIgnoreCase("reload")){
try{
getPlugin().reloadConfig();
......@@ -150,19 +161,22 @@ public class Main extends JavaPlugin{
}
} else if(args[0].equalsIgnoreCase("checkList")){
try{
int test = Integer.parseInt(args[1]) * 5;
int test = 5;
if(args.length > 1){
test = Integer.parseInt(args[1]) * 5;
}
int indice = 0;
sender.sendMessage(CustomConfig.RedStoneClockListHeader.toString().replace("$page", "("+args[1]+"/"+getRDC().getAllLoc().size()/5+")"));
for(Location loc : getRDC().getAllLoc()){
sender.sendMessage(CustomConfig.RedStoneClockListHeader.toString().replace("$page", "("+test/5+"/"+RedstoneClockController.getAllLoc().size()/5+")"));
for(Location loc : RedstoneClockController.getAllLoc()){
if(!(indice > test) && !(indice < test-4)){
if(getRDC().getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.750){
sender.sendMessage("§4RedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+getRDC().getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}else if (getRDC().getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.5){
sender.sendMessage("§eRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+getRDC().getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}else if (getRDC().getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.250){
sender.sendMessage("§aRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+getRDC().getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
if(RedstoneClockController.getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.750){
sender.sendMessage("§4RedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}else if (RedstoneClockController.getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.5){
sender.sendMessage("§eRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}else if (RedstoneClockController.getRedstoneClock(loc).getBoucle() > Main.getMaxImpulsions()*0.250){
sender.sendMessage("§aRedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}else{
sender.sendMessage("§2RedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+getRDC().getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
sender.sendMessage("§2RedStoneClock> §fWorld:"+loc.getWorld().getName()+",X:"+loc.getX()+",Y:"+loc.getY()+",Z:"+loc.getZ()+" b:"+RedstoneClockController.getRedstoneClock(loc).getBoucle()+"/"+getMaxImpulsions());
}
}
indice++;
......@@ -211,7 +225,10 @@ public class Main extends JavaPlugin{
sender.sendMessage(CustomConfig.Prefix+CustomConfig.newValueInConfig.toString().replace("$setting", "\"NotifyAdmins\"").replace("$value", args[1]));
}
}
}else{
CustomConfig.getHelp((Player) sender);
}
/*else if(args[0].equalsIgnoreCase("help")){
}
if(sender instanceof Player){
......@@ -236,10 +253,6 @@ public class Main extends JavaPlugin{
}
public static RedstoneClockController getRDC(){
return instance.rdc;
}
public static int getMaxImpulsions(){
return instance.maxImpulsions;
}
......@@ -256,7 +269,7 @@ public class Main extends JavaPlugin{
instance.delay = delay;
}
public static boolean getNotifyAdmin(){
public static boolean isNotifyAdmin(){
return instance.notifyAdmin;
}
......@@ -264,6 +277,14 @@ public class Main extends JavaPlugin{
instance.notifyAdmin = value;
}
public static boolean isDropItems() {
return instance.DropItems;
}
public static void setDropItems(boolean dropItems) {
instance.DropItems = dropItems;
}
public static String getLine1(){
return instance.line1;
}
......
package com.trafalcraft.antiRedstoneClock.object;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.bukkit.Location;
import com.trafalcraft.antiRedstoneClock.Main;
public class RedstoneClock {
private static SimpleDateFormat formater = new SimpleDateFormat("mm");
private String initTime;
private long endTime;
private int boucle;
int minutes;
private Location loc;
//only for comparator
private boolean lastStatus;
public RedstoneClock(){
initTime = formater.format(new Date());
minutes = Integer.parseInt(initTime);
public RedstoneClock(Location loc){
endTime = (long) System.currentTimeMillis()/1000+Main.getDelay();
boucle = 0;
this.loc = loc;
//only for comparator
lastStatus = false;
}
public void addBoucle(){
......@@ -26,13 +28,28 @@ public class RedstoneClock {
return boucle;
}
public int getMinutes(){
return minutes;
public long getSecondes(){
return endTime;
}
public int getEndTimerInMinutes(){
String endTime = formater.format(new Date());
int endMinutes = Integer.parseInt(endTime)+(Main.getDelay()/60);
return endMinutes;
public Location getLocation(){
return loc;
}
//only for comparator
public void updateStatus(){
if(lastStatus){
lastStatus = false;
}else{
lastStatus = true;
}
}
//only for comparator
public boolean getlastStatus(){
return lastStatus;
}
public boolean isEnd(){
return ((long) System.currentTimeMillis()/1000)>=endTime;
}
}
......@@ -2,6 +2,7 @@ package com.trafalcraft.antiRedstoneClock.object;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;
import org.bukkit.Location;
......@@ -9,53 +10,54 @@ import com.google.common.collect.Maps;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
public class RedstoneClockController {
private final Map<Location, RedstoneClock> activeMap = Maps.newHashMap();
//private static Map<Location, RedstoneClock> activeMap = Maps.newHashMap();
private static ConcurrentMap<Location, RedstoneClock> activeMap = Maps.newConcurrentMap();
public void addRedstone(Location location) throws Exception{
public static void addRedstone(Location location) throws Exception{
if(contains(location)){
throw new Exception(CustomConfig.ERREUR+CustomConfig.duplicate_object.toString());
}else{
activeMap.put(location, new RedstoneClock());
activeMap.put(location, new RedstoneClock(location));
return;
}
}
public boolean contains(Location location){
if(this.activeMap.containsKey(location)){
public static boolean contains(Location location){
if(activeMap.containsKey(location)){
return true;
}
return false;
}
public void removeRedstoneByLocation(Location location){
if(this.activeMap.containsKey(location)){
public static void removeRedstoneByLocation(Location location){
if(activeMap.containsKey(location)){
activeMap.remove(location);
}
}
public void removeRedstoneByObject(RedstoneClock rc){
if(this.activeMap.containsKey(rc)){
activeMap.remove(rc);
public static void removeRedstoneByObject(RedstoneClock rc){
if(activeMap.containsValue(rc)){
activeMap.remove(rc.getLocation());
}
}
public RedstoneClock getRedstoneClock(Location location){
public static RedstoneClock getRedstoneClock(Location location){
return activeMap.get(location);
}
public int size(Location location){
public static int size(Location location){
return activeMap.size();
}
public Map<Location, RedstoneClock> getHashMap(){
public static Map<Location, RedstoneClock> getHashMap(){
return activeMap;
}
public Collection<RedstoneClock> getAll() {
public static Collection<RedstoneClock> getAll() {
return activeMap.values();
}
public Collection<Location> getAllLoc() {
public static Collection<Location> getAllLoc() {
return activeMap.keySet();
}
......
package com.trafalcraft.antiRedstoneClock.util;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import com.trafalcraft.antiRedstoneClock.Main;
public enum CustomConfig {
......@@ -20,16 +23,19 @@ public enum CustomConfig {
//Exception
duplicate_object("This list already contains this redstone");
/*static JavaPlugin plugin = Main.getInstance();
static JavaPlugin plugin = Main.getInstance();
public static void getHelp(Player sender){
sender.sendMessage("");
sender.sendMessage("§3§l-------------------AntiRedstoneClock-------------------");
sender.sendMessage("§3/arc setup <nom de l'arene> §b- crée l'arène.");
sender.sendMessage("§3/arc spawn<numero> §b- Configurer le lieu de spawn des joueurs.");
sender.sendMessage("§3§l-------------AntiRedstoneClock-------------");
sender.sendMessage("§3/arc checkList <nom de l'arene> §b- display the active redstoneclock.");
sender.sendMessage("§3/arc setMaxImpulsion <numero> §b- Change the 0\"MaxImpulsion\" setting.");
sender.sendMessage("§3/arc setDelay <numero> §b- Change the \"Delay\" setting.");
sender.sendMessage("§3/arc notifyAdmin <numero> §b- change the \"notifyAdmin\" setting.");
sender.sendMessage("§3/arc reload <numero> §b- To reload the config file.");
sender.sendMessage(" §3Version: §6" + plugin.getDescription().getVersion());
sender.sendMessage("§3------------------------------------------------");
sender.sendMessage("");
}*/
}
private String value;
......@@ -64,6 +70,7 @@ public enum CustomConfig {
Main.setMaxImpulsions(Main.getPlugin().getConfig().getInt("MaxImpulsion"));
Main.setDelay(Main.getPlugin().getConfig().getInt("Delay"));
Main.setNotifyAdmin(Main.getPlugin().getConfig().getBoolean("NotifyAdmins"));
Main.setDropItems(Main.getPlugin().getConfig().getBoolean("DropItems"));
Main.setLine1(Main.getPlugin().getConfig().getString("Sign.Line1").replace("&", "§"));
Main.setLine2(Main.getPlugin().getConfig().getString("Sign.Line2").replace("&", "§"));
Main.setLine3(Main.getPlugin().getConfig().getString("Sign.Line3").replace("&", "§"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment