Commit c660b9c9 authored by Amosar's avatar Amosar

Add WorldGuard support

parent 4e035066
......@@ -22,6 +22,10 @@ Sign:
#Fr: La list des mondes sur lequel le plugin est desactive separe par des "/", mettre un faut non si aucun
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
Msg:
default:
prefix: '&bAntiRedstoneClock &9&l> &r&b '
......
name: antiRedstoneClock
version: 0.2
version: 0.3
description: Limit the redstoneClock
author: Amosar
......
......@@ -28,9 +28,11 @@ public class Main extends JavaPlugin{
private String line4;
private static ArrayList<String> ignoreWorld = new ArrayList<String>();
private static ArrayList<String> ignoreRegion = new ArrayList<String>();
public void onEnable(){
long startTime = System.nanoTime();
long startTime = System.currentTimeMillis();
instance = this;
plugin = this;
this.rdc = new RedstoneClockController();
......@@ -41,13 +43,21 @@ public class Main extends JavaPlugin{
plugin.saveDefaultConfig();
plugin.reloadConfig();
System.out.println(!getConfig().getString("version").equals("0.2")+"");
if(!getConfig().getString("version").equals("0.2")){
System.out.println("update config file");
getConfig().set("version", "0.2");
getConfig().set("IgnoreWorlds", "redstoneWorld/survival");
plugin.saveConfig();
plugin.reloadConfig();
if(!getConfig().getString("version").equals("0.3")){
if(getConfig().getString("version").equals("0.1")){
System.out.println("update config file to 0.3");
getConfig().set("version", "0.2");
getConfig().set("IgnoreWorlds", "redstoneWorld/survival");
getConfig().set("IgnoreRegions", "redstone/admins");
plugin.saveConfig();
plugin.reloadConfig();
}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");
plugin.saveConfig();
plugin.reloadConfig();
}
}
//if(instance.getConfig().getInt("version") != 0.1){
......@@ -69,6 +79,10 @@ public class Main extends JavaPlugin{
for(int i = 0;i<sIgnoreWorld.split("/").length;i++){
ignoreWorld.add(sIgnoreWorld.split("/")[i]);
}
String sIgnoreRegion = getPlugin().getConfig().getString("IgnoreRegions");
for(int i = 0;i<sIgnoreRegion.split("/").length;i++){
ignoreRegion.add(sIgnoreRegion.split("/")[i]);
}
}catch(YAMLException e){
setMaxImpulsions(150);
setDelay(300);
......@@ -81,12 +95,11 @@ public class Main extends JavaPlugin{
e.printStackTrace();
}
long endTime = System.nanoTime();
long endTime = System.currentTimeMillis();
long duration = (endTime - startTime);
//redstoneOverload();
this.getLogger().info("Plugin chargé en "+duration/1000000+"ms"); //2ms
this.getLogger().info("Plugin chargé en "+duration+"ms"); //2ms
}
private void checkTimer(){
......@@ -145,9 +158,7 @@ public class Main extends JavaPlugin{
public static Main getInstance(){
return instance;
} //if(instance.getConfig().getInt("version") != 0.1){
//plus tard
//}
}
public static JavaPlugin getPlugin(){
return plugin;
}
......@@ -209,9 +220,12 @@ public class Main extends JavaPlugin{
instance.line4 = value;
}
public static Collection<String> getAllowedWorld(){
public static Collection<String> getAllowedWorlds(){
return ignoreWorld;
}
public static Collection<String> getAllowedRegions(){
return ignoreRegion;
}
}
......@@ -14,16 +14,20 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockRedstoneEvent;
import com.trafalcraft.antiRedstoneClock.util.CustomConfig;
import com.trafalcraft.antiRedstoneClock.util.WorldGuardLink;
public class PlayerListener implements Listener {
@EventHandler (priority = EventPriority.LOWEST)
public void onRedstoneClock(BlockRedstoneEvent e){
for(String ignoreWorld:Main.getAllowedWorld()){
for(String ignoreWorld:Main.getAllowedWorlds()){
if(e.getBlock().getWorld().getName().equals(ignoreWorld)){
return;
}
}
if(WorldGuardLink.checkAllowedRegion(e.getBlock().getLocation())){
return;
}
if(e.getBlock().getType() == Material.REDSTONE_WIRE){
if(e.getOldCurrent() == 0){
if(!Main.getRDC().contains(e.getBlock().getLocation())){
......@@ -145,14 +149,12 @@ public class PlayerListener implements Listener {
}
}
}
Main.getRDC().removeRedstoneByLocation(e.getBlock().getLocation());
}
}
}
//Main.getInstance().getLogger().info("Plugin chargé en "+duration/1000000+"ms"); //2ms
}
@EventHandler (priority = EventPriority.HIGHEST)
......@@ -164,5 +166,6 @@ public class PlayerListener implements Listener {
}
}
}
......@@ -7,7 +7,6 @@ import com.trafalcraft.antiRedstoneClock.Main;
public class RedstoneClock {
//Date initTime = SystemClockFactory.getDatetime();
private static SimpleDateFormat formater = new SimpleDateFormat("mm");
private String initTime;
private int boucle;
......
......@@ -65,20 +65,4 @@ public enum CustomConfig {
Main.setLine4(Main.getPlugin().getConfig().getString("Sign.Line4").replace("&", "§"));
}
/*public static void DefaultMsg(){
//default
Main.getPlugin().getConfig().set("Msg.default.prefix", Prefix.toString().replace("§", "&"));
Main.getPlugin().getConfig().set("Msg.default.error", ERREUR.toString().replace("§", "&"));
Main.getPlugin().getConfig().set("Msg.default.no_permission", NO_PERMISSIONS.toString().replace("§", "&"));
Main.getPlugin().getConfig().set("Msg.default.command_use", Command_Use.toString().replace("§", "&"));
Main.getPlugin().getConfig().set("Msg.message.MsgToAdmin", MsgToAdmin.toString().replace("§", "&"));
Main.getPlugin().getConfig().set("Msg.Exception.duplicate_object", duplicate_object.toString().replace("§", "&"));
}*/
/* void set(String value) {
//this.value = value;
}
*/
}
\ No newline at end of file
package com.trafalcraft.antiRedstoneClock.util;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.trafalcraft.antiRedstoneClock.Main;
public class WorldGuardLink {
private static WorldGuardPlugin getWorldGuard() {
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
// WorldGuard may not be loaded
if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
return null; // Maybe you want throw an exception instead
}
return (WorldGuardPlugin) plugin;
}
public static boolean checkAllowedRegion(Location loc){
if(getWorldGuard() == null){
return false;
}
if(getWorldGuard().getRegionManager(loc.getWorld()) != null){
RegionManager worldGuard = getWorldGuard().getRegionManager(loc.getWorld());
ApplicableRegionSet regions = worldGuard.getApplicableRegions(loc);
for(String ignoreRegion:Main.getAllowedRegions()){
for(ProtectedRegion region : regions.getRegions()){
if(region.getId().equals(ignoreRegion)){
return true;
}
}
}
}
return false;
}
}
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