mirror of
https://github.com/Maxlego08/zKoth.git
synced 2024-11-26 12:35:17 +01:00
Mise à jour du code sur git
This commit is contained in:
parent
08a760e5c2
commit
a998cffbe0
@ -1,7 +1,7 @@
|
||||
name: zKoth
|
||||
author: Maxlego08
|
||||
main: fr.maxlego08.zkoth.ZKothPlugin
|
||||
version: 2.0.1.1
|
||||
version: 2.0.1.3
|
||||
softdepend: [PlaceholderAPI, Guilds, Factions, FactionsX, SuperiorSkyblock2, LegacyFactions, FeatherBoard, TAB, TitleManager, UltimateFactions]
|
||||
commands:
|
||||
api-version: 1.13
|
@ -153,6 +153,24 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(boolean now) {
|
||||
|
||||
if (this.minLocation == null || this.maxLocation == null) {
|
||||
return;
|
||||
} else if (this.isCooldown) {
|
||||
return;
|
||||
} else if (this.isEnable) {
|
||||
return;
|
||||
} else {
|
||||
if (now)
|
||||
spawnNow();
|
||||
else
|
||||
spawn();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void spawn() {
|
||||
|
||||
this.isCooldown = true;
|
||||
@ -404,7 +422,7 @@ public class ZKoth extends ZUtils implements Koth {
|
||||
|
||||
this.commands.forEach(command -> {
|
||||
command = replaceMessage(command);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), papi(command, player));
|
||||
});
|
||||
|
||||
Location center = cuboid.getCenter();
|
||||
|
@ -2,6 +2,7 @@ package fr.maxlego08.zkoth;
|
||||
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
import be.maximvdw.featherboard.ch;
|
||||
import fr.maxlego08.zkoth.api.KothManager;
|
||||
import fr.maxlego08.zkoth.command.CommandManager;
|
||||
import fr.maxlego08.zkoth.command.commands.CommandKoth;
|
||||
@ -9,6 +10,7 @@ import fr.maxlego08.zkoth.inventory.InventoryManager;
|
||||
import fr.maxlego08.zkoth.listener.AdapterListener;
|
||||
import fr.maxlego08.zkoth.save.Config;
|
||||
import fr.maxlego08.zkoth.save.MessageLoader;
|
||||
import fr.maxlego08.zkoth.scheduler.SchedulerManager;
|
||||
import fr.maxlego08.zkoth.scoreboard.ScoreBoardManager;
|
||||
import fr.maxlego08.zkoth.scoreboard.implementations.FeatherBoardHook;
|
||||
import fr.maxlego08.zkoth.scoreboard.implementations.TabPremiumHook;
|
||||
@ -18,6 +20,7 @@ import fr.maxlego08.zkoth.zcore.logger.Logger;
|
||||
import fr.maxlego08.zkoth.zcore.logger.Logger.LogType;
|
||||
import fr.maxlego08.zkoth.zcore.utils.plugins.Metrics;
|
||||
import fr.maxlego08.zkoth.zcore.utils.plugins.Plugins;
|
||||
import fr.maxlego08.zkoth.zcore.utils.plugins.VersionChecker;
|
||||
|
||||
/**
|
||||
* System to create your plugins very simply Projet:
|
||||
@ -29,6 +32,7 @@ import fr.maxlego08.zkoth.zcore.utils.plugins.Plugins;
|
||||
public class ZKothPlugin extends ZPlugin {
|
||||
|
||||
private KothManager kothManager;
|
||||
private SchedulerManager scheduler;
|
||||
private final MessageLoader messageLoader = new MessageLoader(this);
|
||||
|
||||
@Override
|
||||
@ -38,6 +42,7 @@ public class ZKothPlugin extends ZPlugin {
|
||||
|
||||
this.scoreboardManager = new ScoreBoardManager();
|
||||
this.kothManager = new ZKothManager(this.scoreboardManager);
|
||||
this.scheduler = new SchedulerManager(this.kothManager);
|
||||
|
||||
this.getServer().getServicesManager().register(KothManager.class, kothManager, this, ServicePriority.High);
|
||||
|
||||
@ -59,6 +64,7 @@ public class ZKothPlugin extends ZPlugin {
|
||||
addSave(Config.getInstance());
|
||||
addSave((ZKothManager) kothManager);
|
||||
addSave(messageLoader);
|
||||
addSave(scheduler);
|
||||
|
||||
if (this.isEnable(Plugins.FEATHERBOARD)) {
|
||||
this.scoreboardManager.setScoreboard(new FeatherBoardHook());
|
||||
@ -87,6 +93,9 @@ public class ZKothPlugin extends ZPlugin {
|
||||
|
||||
new Metrics(this, 6924);
|
||||
|
||||
VersionChecker checker = new VersionChecker(this, 9);
|
||||
checker.useLastVersion();
|
||||
|
||||
postEnable();
|
||||
}
|
||||
|
||||
@ -110,4 +119,8 @@ public class ZKothPlugin extends ZPlugin {
|
||||
return kothManager;
|
||||
}
|
||||
|
||||
public SchedulerManager getSchedulerManager() {
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -102,6 +102,12 @@ public interface Koth {
|
||||
*/
|
||||
public void spawn(CommandSender sender, boolean now);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param now
|
||||
*/
|
||||
public void spawn(boolean now);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
|
@ -2,6 +2,7 @@ package fr.maxlego08.zkoth.command.commands;
|
||||
|
||||
import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.command.VCommand;
|
||||
import fr.maxlego08.zkoth.command.commands.scheduler.CommandKothScheduler;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.commands.CommandType;
|
||||
@ -27,6 +28,7 @@ public class CommandKoth extends VCommand {
|
||||
this.addSubCommand(new CommandKothSetCapture());
|
||||
this.addSubCommand(new CommandKothAxe());
|
||||
this.addSubCommand(new CommandKothVersion());
|
||||
this.addSubCommand(new CommandKothScheduler());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,33 @@
|
||||
package fr.maxlego08.zkoth.command.commands.scheduler;
|
||||
|
||||
import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.command.VCommand;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.commands.CommandType;
|
||||
|
||||
public class CommandKothScheduler extends VCommand {
|
||||
|
||||
public CommandKothScheduler() {
|
||||
this.setPermission(Permission.ZKOTH_SCHEDULER);
|
||||
this.setDescription(Message.DESCRIPTION_SCHEDULER);
|
||||
this.addSubCommand("scheduler", "s");
|
||||
this.addSubCommand(new CommandKothSchedulerList());
|
||||
this.addSubCommand(new CommandKothSchedulerAdd());
|
||||
this.addSubCommand(new CommandKothSchedulerRemove());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandType perform(ZKothPlugin main) {
|
||||
|
||||
this.subVCommands.forEach(command -> {
|
||||
String message = Message.COMMAND_SYNTAXE_HELP.getMessage();
|
||||
message = message.replace("%command%", command.getSyntaxe());
|
||||
message = message.replace("%description%", command.getDescription());
|
||||
messageWO(sender, message);
|
||||
});
|
||||
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package fr.maxlego08.zkoth.command.commands.scheduler;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.api.Koth;
|
||||
import fr.maxlego08.zkoth.command.VCommand;
|
||||
import fr.maxlego08.zkoth.scheduler.Scheduler;
|
||||
import fr.maxlego08.zkoth.scheduler.SchedulerType;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.commands.CommandType;
|
||||
|
||||
public class CommandKothSchedulerAdd extends VCommand {
|
||||
|
||||
public CommandKothSchedulerAdd() {
|
||||
this.setPermission(Permission.ZKOTH_SCHEDULER);
|
||||
this.setDescription(Message.DESCRIPTION_SCHEDULER_ADD);
|
||||
this.addSubCommand("add");
|
||||
this.addRequireArg("delay/repeat");
|
||||
this.addRequireArg("koth name");
|
||||
this.addOptionalArg("day");
|
||||
this.addOptionalArg("hour");
|
||||
this.addOptionalArg("minute");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandType perform(ZKothPlugin main) {
|
||||
|
||||
SchedulerType type = SchedulerType.valueOf(argAsString(0).toUpperCase());
|
||||
Optional<Koth> optional = main.getKothManager().getKoth(argAsString(1));
|
||||
|
||||
if (!optional.isPresent()) {
|
||||
message(sender, Message.ZKOTH_DOESNT_EXIST);
|
||||
return CommandType.DEFAULT;
|
||||
}
|
||||
|
||||
Koth totem = optional.get();
|
||||
Scheduler scheduler;
|
||||
switch (type) {
|
||||
case DELAY:
|
||||
|
||||
String day = argAsString(2);
|
||||
|
||||
if (!isDay(day)) {
|
||||
message(sender, Message.KOTH_SCHEDULER_ERROR, day);
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
int hour = argAsInteger(3);
|
||||
int minute = argAsInteger(4);
|
||||
|
||||
scheduler = new Scheduler(type, day, hour, minute, totem.getName());
|
||||
|
||||
break;
|
||||
case REPEAT:
|
||||
|
||||
minute = argAsInteger(2);
|
||||
scheduler = new Scheduler(type, minute, totem.getName());
|
||||
|
||||
break;
|
||||
default:
|
||||
return CommandType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
main.getSchedulerManager().addScheduler(sender, scheduler);
|
||||
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package fr.maxlego08.zkoth.command.commands.scheduler;
|
||||
|
||||
import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.command.VCommand;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.commands.CommandType;
|
||||
|
||||
public class CommandKothSchedulerList extends VCommand {
|
||||
|
||||
public CommandKothSchedulerList() {
|
||||
this.setPermission(Permission.ZKOTH_SCHEDULER);
|
||||
this.setDescription(Message.DESCRIPTION_SCHEDULER_LIST);
|
||||
this.addSubCommand("list");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandType perform(ZKothPlugin main) {
|
||||
|
||||
main.getSchedulerManager().show(sender);
|
||||
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package fr.maxlego08.zkoth.command.commands.scheduler;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import fr.maxlego08.zkoth.ZKothPlugin;
|
||||
import fr.maxlego08.zkoth.command.VCommand;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Permission;
|
||||
import fr.maxlego08.zkoth.zcore.utils.commands.CommandType;
|
||||
|
||||
public class CommandKothSchedulerRemove extends VCommand {
|
||||
|
||||
public CommandKothSchedulerRemove() {
|
||||
this.setPermission(Permission.ZKOTH_SCHEDULER);
|
||||
this.setDescription(Message.DESCRIPTION_SCHEDULER_REMOVE);
|
||||
this.addSubCommand("remove");
|
||||
this.addRequireArg("UUID");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandType perform(ZKothPlugin main) {
|
||||
|
||||
UUID uuid = UUID.fromString(argAsString(0));
|
||||
main.getSchedulerManager().remove(sender, uuid);
|
||||
|
||||
return CommandType.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
108
src/fr/maxlego08/zkoth/scheduler/Scheduler.java
Normal file
108
src/fr/maxlego08/zkoth/scheduler/Scheduler.java
Normal file
@ -0,0 +1,108 @@
|
||||
package fr.maxlego08.zkoth.scheduler;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import fr.maxlego08.zkoth.zcore.utils.ZUtils;
|
||||
|
||||
public class Scheduler extends ZUtils{
|
||||
|
||||
private final SchedulerType type;
|
||||
private final String day;
|
||||
private final int hour;
|
||||
private final int minutes;
|
||||
private final String totemName;
|
||||
private long lastCreate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* @param day
|
||||
* @param hour
|
||||
* @param minutes
|
||||
* @param totemName
|
||||
*/
|
||||
public Scheduler(SchedulerType type, String day, int hour, int minutes, String totemName) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.day = day;
|
||||
this.hour = hour;
|
||||
this.minutes = minutes;
|
||||
this.totemName = totemName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param type
|
||||
* @param hour
|
||||
* @param totemName
|
||||
*/
|
||||
public Scheduler(SchedulerType type, int minute, String totemName) {
|
||||
this(type, null, 0, minute, totemName);
|
||||
lastCreate = System.currentTimeMillis() + (1000 * 60 * minute);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastCreate
|
||||
*/
|
||||
public long getLastCreate() {
|
||||
return lastCreate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the totemName
|
||||
*/
|
||||
public String getTotemName() {
|
||||
return totemName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public SchedulerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the day
|
||||
*/
|
||||
public String getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hour
|
||||
*/
|
||||
public int getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minutes
|
||||
*/
|
||||
public int getMinutes() {
|
||||
return minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param calendar
|
||||
* @return
|
||||
*/
|
||||
public boolean toggle(Calendar calendar) {
|
||||
|
||||
switch (type) {
|
||||
case DELAY:
|
||||
return (calendar.get(Calendar.HOUR_OF_DAY) == hour && calendar.get(Calendar.MINUTE) == minutes
|
||||
&& super.getDay().equalsIgnoreCase(day));
|
||||
case REPEAT:
|
||||
if (lastCreate != 0 && System.currentTimeMillis() > lastCreate) {
|
||||
lastCreate = System.currentTimeMillis() + (1000 * 60 * minutes);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
204
src/fr/maxlego08/zkoth/scheduler/SchedulerManager.java
Normal file
204
src/fr/maxlego08/zkoth/scheduler/SchedulerManager.java
Normal file
@ -0,0 +1,204 @@
|
||||
package fr.maxlego08.zkoth.scheduler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.maxlego08.zkoth.api.Koth;
|
||||
import fr.maxlego08.zkoth.api.KothManager;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.logger.Logger;
|
||||
import fr.maxlego08.zkoth.zcore.logger.Logger.LogType;
|
||||
import fr.maxlego08.zkoth.zcore.utils.ZUtils;
|
||||
import fr.maxlego08.zkoth.zcore.utils.builder.TimerBuilder;
|
||||
import fr.maxlego08.zkoth.zcore.utils.storage.Persist;
|
||||
import fr.maxlego08.zkoth.zcore.utils.storage.Saveable;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent.Action;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
public class SchedulerManager extends ZUtils implements Saveable {
|
||||
|
||||
private static List<Scheduler> schedulers = new ArrayList<Scheduler>();
|
||||
private transient Map<UUID, Scheduler> map = new HashMap<>();
|
||||
private transient boolean isRunning = false;
|
||||
private final transient KothManager manager;
|
||||
|
||||
public SchedulerManager(KothManager manager) {
|
||||
super();
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(Persist persist) {
|
||||
persist.save(this, "schedulers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(Persist persist) {
|
||||
persist.loadOrSaveDefault(this, SchedulerManager.class, "schedulers");
|
||||
run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajout d'un scheduler
|
||||
*
|
||||
* @param sender
|
||||
* @param scheduler
|
||||
*/
|
||||
public void addScheduler(CommandSender sender, Scheduler scheduler) {
|
||||
|
||||
schedulers.add(scheduler);
|
||||
message(sender, Message.ZKOTH_SCHEDULER_CREATE, scheduler.getTotemName());
|
||||
run();
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
if (isRunning)
|
||||
return;
|
||||
|
||||
isRunning = true;
|
||||
|
||||
scheduleFix(1000, (task, canRun) -> {
|
||||
|
||||
if (!canRun || !isRunning || schedulers.size() == 0) {
|
||||
task.cancel();
|
||||
isRunning = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Iterator<Scheduler> iterator = schedulers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
Scheduler scheduler = iterator.next();
|
||||
if (scheduler.toggle(calendar)) {
|
||||
|
||||
Optional<Koth> optional = manager.getKoth(scheduler.getTotemName());
|
||||
|
||||
if (!optional.isPresent()) {
|
||||
Logger.info("Deleting a scheduler, unable to find the koth " + scheduler.getTotemName(),
|
||||
LogType.ERROR);
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
Koth koth = optional.get();
|
||||
koth.spawn(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sc
|
||||
* @return
|
||||
*/
|
||||
private UUID getUUID(Scheduler sc) {
|
||||
for (Entry<UUID, Scheduler> e : map.entrySet())
|
||||
if (e.getValue().equals(sc))
|
||||
return e.getKey();
|
||||
return UUID.randomUUID();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender
|
||||
* @param uuid
|
||||
*/
|
||||
public void remove(CommandSender sender, UUID uuid) {
|
||||
|
||||
if (!map.containsKey(uuid)) {
|
||||
message(sender, Message.ZKOTH_SCHEDULER_REMOVE_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
Scheduler scheduler = map.get(uuid);
|
||||
|
||||
schedulers.remove(scheduler);
|
||||
map.remove(uuid);
|
||||
|
||||
message(sender, Message.ZKOTH_SCHEDULER_REMOVE_SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender
|
||||
*/
|
||||
public void show(CommandSender sender) {
|
||||
|
||||
if (schedulers.size() == 0) {
|
||||
|
||||
message(sender, Message.ZKOTH_SCHEDULER_EMPTY);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
|
||||
schedulers.forEach(sc -> {
|
||||
|
||||
String message = "";
|
||||
if (sc.getType().equals(SchedulerType.DELAY)) {
|
||||
message = Message.ZKOTH_SCHEDULER_LIST.getMessage().replace("%totemName%", sc.getTotemName())
|
||||
.replace("%type%", sc.getType().name()).replace("%hour%", String.valueOf(sc.getHour()))
|
||||
.replace("%minute%", String.valueOf(sc.getMinutes())).replace("%day%", sc.getDay());
|
||||
} else {
|
||||
message = Message.ZKOTH_SCHEDULER_LIST_REPEAT.getMessage().replace("%type%", sc.getType().name())
|
||||
.replace("%totemName%", sc.getTotemName())
|
||||
.replace("%timer%", TimerBuilder.getStringTime(sc.getMinutes() * 60));
|
||||
}
|
||||
|
||||
UUID uuid = getUUID(sc);
|
||||
map.putIfAbsent(uuid, sc);
|
||||
|
||||
TextComponent component = new TextComponent(message);
|
||||
component.setHoverEvent(new HoverEvent(Action.SHOW_TEXT,
|
||||
new TextComponent[] { new TextComponent(Message.ZKOTH_SCHEDULER_REMOVE_HOVER.getMessage()) }));
|
||||
component.setClickEvent(new ClickEvent(net.md_5.bungee.api.chat.ClickEvent.Action.SUGGEST_COMMAND,
|
||||
"/koth scheduler remove " + uuid));
|
||||
|
||||
((Player) sender).spigot().sendMessage(component);
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
schedulers.forEach(sc -> {
|
||||
|
||||
if (sc.getType().equals(SchedulerType.DELAY)) {
|
||||
message(sender, Message.ZKOTH_SCHEDULER_LIST.getMessage().replace("%totemName%", sc.getTotemName())
|
||||
.replace("%type%", sc.getType().name()).replace("%hour%", String.valueOf(sc.getHour()))
|
||||
.replace("%minute%", String.valueOf(sc.getMinutes())).replace("%day%", sc.getDay()));
|
||||
} else {
|
||||
message(sender,
|
||||
Message.ZKOTH_SCHEDULER_LIST_REPEAT.getMessage().replace("%type%", sc.getType().name())
|
||||
.replace("%totemName%", sc.getTotemName())
|
||||
.replace("%timer%", TimerBuilder.getStringTime(sc.getMinutes() * 60)));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
8
src/fr/maxlego08/zkoth/scheduler/SchedulerType.java
Normal file
8
src/fr/maxlego08/zkoth/scheduler/SchedulerType.java
Normal file
@ -0,0 +1,8 @@
|
||||
package fr.maxlego08.zkoth.scheduler;
|
||||
|
||||
public enum SchedulerType {
|
||||
|
||||
REPEAT,
|
||||
DELAY
|
||||
|
||||
}
|
@ -91,6 +91,20 @@ public enum Message {
|
||||
ZKOHT_EVENT_PLAYER("Person"),
|
||||
ZKOTH_EVENT_DISABLE("§cThe event is not enable."),
|
||||
|
||||
ZKOTH_SCHEDULER_CREATE("§eYou have just created a scheduler for the koth §6%s§e."),
|
||||
ZKOTH_SCHEDULER_EMPTY("§cNo scheduler available"),
|
||||
ZKOTH_SCHEDULER_REMOVE_HOVER("§7Click to delete the scheduler"),
|
||||
ZKOTH_SCHEDULER_LIST("§6%totemName%§7, §f%type%§7, §e%day%§7, §e%hour%§7, §e%minute%"),
|
||||
ZKOTH_SCHEDULER_LIST_REPEAT("§6%totemName%§7, §f%type%§7, §e%timer%"),
|
||||
ZKOTH_SCHEDULER_REMOVE_ERROR("§cYou must make /koth scheduler list and then click on one of the koths to be able to delete it"),
|
||||
ZKOTH_SCHEDULER_REMOVE_SUCCESS("§eYou have just deleted the scheduler"),
|
||||
|
||||
DESCRIPTION_SCHEDULER("Show scheduler commands"),
|
||||
DESCRIPTION_SCHEDULER_LIST("Show scheduler list"),
|
||||
DESCRIPTION_SCHEDULER_ADD("Add a scheduler"),
|
||||
DESCRIPTION_SCHEDULER_REMOVE("Remove a scheduler"),
|
||||
KOTH_SCHEDULER_ERROR("§cImpossible to find the day §f%s§c."),
|
||||
|
||||
;
|
||||
|
||||
private List<String> messages;
|
||||
|
@ -18,6 +18,7 @@ public enum Permission {
|
||||
ZKOTH_LOOT,
|
||||
ZKOTH_TYPE,
|
||||
ZKOTH_SETCAPTURE,
|
||||
ZKOTH_SCHEDULER,
|
||||
|
||||
;
|
||||
|
||||
|
@ -7,7 +7,10 @@ import java.text.DecimalFormatSymbols;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@ -304,7 +307,6 @@ public abstract class ZUtils extends MessageUtils {
|
||||
return decimalFormat.format(decimal);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
@ -1218,4 +1220,34 @@ public abstract class ZUtils extends MessageUtils {
|
||||
});
|
||||
}
|
||||
|
||||
protected String getDay() {
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(new Date());
|
||||
int today = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
switch (today) {
|
||||
case GregorianCalendar.MONDAY:
|
||||
return "MONDAY";
|
||||
case GregorianCalendar.TUESDAY:
|
||||
return "TUESDAY";
|
||||
case GregorianCalendar.WEDNESDAY:
|
||||
return "WEDNESDAY";
|
||||
case GregorianCalendar.THURSDAY:
|
||||
return "THURSDAY";
|
||||
case GregorianCalendar.FRIDAY:
|
||||
return "FRIDAY";
|
||||
case GregorianCalendar.SATURDAY:
|
||||
return "SATURDAY";
|
||||
case GregorianCalendar.SUNDAY:
|
||||
return "SUNDAY";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isDay(String day) {
|
||||
return day.equalsIgnoreCase("MONDAY") || day.equalsIgnoreCase("TUESDAY") || day.equalsIgnoreCase("WEDNESDAY")
|
||||
|| day.equalsIgnoreCase("THURSDAY") || day.equalsIgnoreCase("FRIDAY")
|
||||
|| day.equalsIgnoreCase("SATURDAY") || day.equalsIgnoreCase("SUNDAY");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,94 +1,113 @@
|
||||
package fr.maxlego08.zkoth.zcore.utils.plugins;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import fr.maxlego08.zkoth.listener.ListenerAdapter;
|
||||
import fr.maxlego08.zkoth.zcore.enums.Message;
|
||||
import fr.maxlego08.zkoth.zcore.logger.Logger;
|
||||
|
||||
public class VersionChecker extends ListenerAdapter {
|
||||
|
||||
private final Plugin plugin;
|
||||
|
||||
/**
|
||||
* @param plugin
|
||||
* @param useLastVersion
|
||||
*
|
||||
* @author Maxlego08
|
||||
*
|
||||
*/
|
||||
public VersionChecker(Plugin plugin) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
}
|
||||
public class VersionChecker implements Listener {
|
||||
|
||||
private final String URL_API = "https://groupez.dev/api/v1/resource/version/%s";
|
||||
private final String URL_RESOURCE = "https://groupez.dev/resources/%s";
|
||||
private final Plugin plugin;
|
||||
private final int pluginID;
|
||||
private boolean useLastVersion = false;
|
||||
|
||||
public void useLastVersion(Plugin plugin) {
|
||||
UpdateChecker checker = new UpdateChecker(plugin, 74073);
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param plugin
|
||||
* @param pluginID
|
||||
*/
|
||||
public VersionChecker(Plugin plugin, int pluginID) {
|
||||
super();
|
||||
this.plugin = plugin;
|
||||
this.pluginID = pluginID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to check if the plugin version is up to date.
|
||||
*/
|
||||
public void useLastVersion() {
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(this, this.plugin); // Register
|
||||
// event
|
||||
|
||||
String pluginVersion = plugin.getDescription().getVersion();
|
||||
AtomicBoolean atomicBoolean = new AtomicBoolean();
|
||||
checker.getVersion(version -> {
|
||||
this.getVersion(version -> {
|
||||
|
||||
long ver = Long.valueOf(version.replace(".", ""));
|
||||
long plVersion = Long.valueOf(plugin.getDescription().getVersion().replace(".", ""));
|
||||
long plVersion = Long.valueOf(pluginVersion.replace(".", ""));
|
||||
atomicBoolean.set(plVersion >= ver);
|
||||
useLastVersion = atomicBoolean.get();
|
||||
this.useLastVersion = atomicBoolean.get();
|
||||
if (atomicBoolean.get())
|
||||
Logger.info("There is not a new update available.");
|
||||
else
|
||||
Logger.info("There is a new update available. Your version: " + plugin.getDescription().getVersion()
|
||||
+ ", Laste version: " + version);
|
||||
Logger.info("No update available.");
|
||||
else {
|
||||
Logger.info("New update available. Your version: " + pluginVersion + ", latest version: " + version);
|
||||
Logger.info("Download plugin here: " + String.format(URL_RESOURCE, this.pluginID));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConnect(PlayerJoinEvent event, Player player) {
|
||||
@EventHandler
|
||||
public void onConnect(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (!useLastVersion && event.getPlayer().hasPermission("zplugin.notifs")) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!useLastVersion && event.getPlayer().hasPermission("zplugin.notifs")) {
|
||||
message(player,
|
||||
"§cYou do not use the latest version of the plugin! Thank you for taking the latest version to avoid any risk of problem!");
|
||||
}
|
||||
String prefix = Message.PREFIX.getMessage();
|
||||
player.sendMessage(prefix
|
||||
+ "§cYou do not use the latest version of the plugin! Thank you for taking the latest version to avoid any risk of problem!");
|
||||
player.sendMessage(prefix + "§fDownload plugin here: §a" + String.format(URL_RESOURCE, pluginID));
|
||||
}
|
||||
}.runTaskLater(plugin, 20 * 2);
|
||||
}
|
||||
|
||||
public class UpdateChecker {
|
||||
|
||||
private Plugin plugin;
|
||||
private int resourceId;
|
||||
|
||||
public UpdateChecker(Plugin plugin, int resourceId) {
|
||||
this.plugin = plugin;
|
||||
this.resourceId = resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version by plugin id
|
||||
*
|
||||
* @param consumer
|
||||
* - Do something after
|
||||
*/
|
||||
public void getVersion(final Consumer<String> consumer) {
|
||||
public void getVersion(Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
try (InputStream inputStream = new URL(
|
||||
"https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream();
|
||||
Scanner scanner = new Scanner(inputStream)) {
|
||||
if (scanner.hasNext()) {
|
||||
final String apiURL = String.format(URL_API, this.pluginID);
|
||||
try {
|
||||
URL url = new URL(apiURL);
|
||||
URLConnection hc = url.openConnection();
|
||||
hc.setRequestProperty("User-Agent",
|
||||
"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
|
||||
Scanner scanner = new Scanner(hc.getInputStream());
|
||||
if (scanner.hasNext())
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
scanner.close();
|
||||
|
||||
} catch (IOException exception) {
|
||||
this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user