102 lines
3.7 KiB
Java
102 lines
3.7 KiB
Java
package ru.redguy.extendedpistons; //TODO: slime sides chests move, power supply remove, refactor
|
|
|
|
import net.milkbowl.vault.permission.Permission;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.Instant;
|
|
import java.util.*;
|
|
|
|
public final class ExtendedPistons extends JavaPlugin {
|
|
|
|
public static ExtendedPistons INSTANCE;
|
|
|
|
public FileConfiguration conf;
|
|
public Permission permsService = null;
|
|
public SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
|
public SimpleDateFormat dayOfWeek = new SimpleDateFormat("EEE",Locale.ENGLISH);
|
|
public HashMap<String,ArrayList<Period>> weekPeriods;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
INSTANCE = this;
|
|
|
|
conf = getConfig();
|
|
if(!conf.isSet("piston-move-limitations"))
|
|
conf.set("piston-move-limitations",new HashMap<String, Integer>() {{
|
|
put("default", 8);
|
|
put("vip", 12);
|
|
put("premium", 20);
|
|
}});
|
|
if(!conf.isSet("enabled-times.Mon"))
|
|
conf.set("enabled-times.Mon",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Tue"))
|
|
conf.set("enabled-times.Tue",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Wed"))
|
|
conf.set("enabled-times.Wed",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Thu"))
|
|
conf.set("enabled-times.Thu",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Fri"))
|
|
conf.set("enabled-times.Fri",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Sat"))
|
|
conf.set("enabled-times.Sat",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("enabled-times.Sun"))
|
|
conf.set("enabled-times.Sun",new ArrayList<String>() {{add("14:00-18:00");}});
|
|
if(!conf.isSet("sticky-piston-pulls-chest"))
|
|
conf.set("sticky-piston-pulls-chest",true);
|
|
|
|
saveConfig();
|
|
|
|
weekPeriods = new HashMap<>();
|
|
parsePeriods("Mon");
|
|
parsePeriods("Tue");
|
|
parsePeriods("Wed");
|
|
parsePeriods("Thu");
|
|
parsePeriods("Fri");
|
|
parsePeriods("Sat");
|
|
parsePeriods("Sun");
|
|
|
|
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
|
permsService = rsp.getProvider();
|
|
|
|
Bukkit.getPluginManager().registerEvents(new WorldListener(), this);
|
|
}
|
|
|
|
public void parsePeriods(String dow) {
|
|
List<String> times = conf.getStringList("enabled-times."+dow);
|
|
ArrayList<Period> periods = new ArrayList<>();
|
|
for (String time : times) {
|
|
try {
|
|
String[] t = time.split("-");
|
|
periods.add(new Period(sdf.parse(t[0]), sdf.parse(t[1])));
|
|
} catch (ParseException e) {
|
|
getLogger().warning("Unable to parse time period :"+time);
|
|
}
|
|
}
|
|
weekPeriods.put(dow,periods);
|
|
}
|
|
|
|
public boolean isAllowedTime() {
|
|
String dow = dayOfWeek.format(Calendar.getInstance(Locale.ENGLISH).getTime());
|
|
ArrayList<Period> periods = weekPeriods.get(dow);
|
|
Instant now = Instant.now();
|
|
for (Period period : periods) {
|
|
if(period.isBehind(now)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean isStickyPistonPulls() {
|
|
return conf.getBoolean("sticky-piston-pulls-chest");
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
|
|
}
|
|
}
|