Skip to content

Commit 6473cb0

Browse files
authored
1.0.0 SNAPSHOT
Main project files
1 parent b33592f commit 6473cb0

File tree

12 files changed

+186
-0
lines changed

12 files changed

+186
-0
lines changed

bin/com/geik/timer/Commands.class

1.65 KB
Binary file not shown.

bin/com/geik/timer/Main.class

1.38 KB
Binary file not shown.

bin/com/geik/timer/Task$1.class

753 Bytes
Binary file not shown.

bin/com/geik/timer/Task$2.class

486 Bytes
Binary file not shown.

bin/com/geik/timer/Task.class

3.74 KB
Binary file not shown.

bin/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# You have to open HaveDate setting if you want to use it only one day.
2+
Tasks:
3+
0:
4+
Time: '22:04:00'
5+
HaveDate: true
6+
Day: 'Mon'
7+
Command:
8+
- 'say This is a task for 22:04:00 only for Monday'
9+
1:
10+
Time: '22:04:05'
11+
HaveDate: false
12+
Day: ''
13+
Command:
14+
- 'say This is a task for 22:04:05 every day'

bin/plugin.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: TaskScheduler
2+
main: com.geik.timer.Main
3+
version: 1.0
4+
author: Geik
5+
commands:
6+
taskscheduler:
7+
description: Reload the config of scheduler

src/com/geik/timer/Commands.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.geik.timer;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
import org.bukkit.entity.Player;
7+
8+
public class Commands implements CommandExecutor{
9+
10+
private Main plugin;
11+
protected Commands(Main plugin) {
12+
this.plugin = plugin;}
13+
14+
15+
16+
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
17+
if (label.equalsIgnoreCase("taskscheduler")){
18+
if (sender instanceof Player){
19+
Player player = (Player) sender;
20+
if (player.hasPermission("task.scheduler")){
21+
plugin.reloadConfig();
22+
player.sendMessage(Main.color("&2&lScheduler &aConfig has loaded successfully."));
23+
Task.taskid.cancel();
24+
Task.taskAgain();
25+
}
26+
else {
27+
player.sendMessage(Main.color("&2&lScheduler &cYou do not have enought perm for execute this command."));
28+
}
29+
}
30+
else {
31+
plugin.reloadConfig();
32+
sender.sendMessage(Main.color("&2&lScheduler &aConfig has loaded successfully."));
33+
Task.taskid.cancel();
34+
Task.taskAgain();}
35+
}
36+
37+
return false;
38+
}
39+
}

src/com/geik/timer/Main.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.geik.timer;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.ChatColor;
5+
import org.bukkit.plugin.java.JavaPlugin;
6+
7+
8+
public class Main extends JavaPlugin{
9+
10+
public static Main instance;
11+
12+
public void onEnable()
13+
{
14+
instance = this;
15+
getCommand("taskscheduler").setExecutor(new Commands(this));
16+
saveDefaultConfig();
17+
Task.taskAgain();
18+
Bukkit.getConsoleSender().sendMessage(color("&6&lTaskScheduler &aLoaded! Version: 1.0"));
19+
Bukkit.getConsoleSender().sendMessage(color("&6&lTaskScheduler &aMade by Geik."));
20+
}
21+
public void onDisable()
22+
{
23+
}
24+
25+
public static String color(String yazirengi){return ChatColor.translateAlternateColorCodes('&', yazirengi);}
26+
}

src/com/geik/timer/Task.java

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.geik.timer;
2+
3+
import java.io.File;
4+
import java.text.SimpleDateFormat;
5+
import java.util.Date;
6+
7+
import org.bukkit.Bukkit;
8+
import org.bukkit.configuration.file.FileConfiguration;
9+
import org.bukkit.configuration.file.YamlConfiguration;
10+
import org.bukkit.scheduler.BukkitRunnable;
11+
12+
public class Task {
13+
@SuppressWarnings("unused")
14+
private Main plugin;
15+
16+
public Task(Main plugin) {
17+
this.plugin = plugin;
18+
}
19+
20+
private static SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
21+
private static SimpleDateFormat formatx = new SimpleDateFormat("EEE");
22+
static int k = 0;
23+
24+
public static boolean hasTime() {
25+
File c = new File("plugins/TaskScheduler/config.yml");
26+
FileConfiguration cfg = YamlConfiguration.loadConfiguration(c);
27+
for (String s : cfg.getConfigurationSection("Tasks").getKeys(false)) {
28+
if (Task.format.format(new Date()).equals(cfg.getString("Tasks." + s + ".Time"))) {
29+
if (cfg.getBoolean("Tasks." + s + ".HaveDate")) {
30+
if (Task.formatx.format(new Date()).equals(cfg.getString("Tasks." + s + ".Day"))) {
31+
k = Integer.valueOf(s);
32+
return true;
33+
}
34+
} else {
35+
k = Integer.valueOf(s);
36+
return true;
37+
}
38+
}
39+
}
40+
return false;
41+
}
42+
43+
public static BukkitRunnable taskid;
44+
45+
public static void taskAgain() {
46+
if (taskid != null) {
47+
taskid.cancel();
48+
taskid = null;
49+
}
50+
taskid = new BukkitRunnable() {
51+
@Override
52+
public synchronized void cancel() throws IllegalStateException {
53+
super.cancel();
54+
}
55+
56+
public void run() {
57+
if (Task.hasTime()) {
58+
runix();
59+
taskid.cancel();
60+
}
61+
}
62+
};
63+
taskid.runTaskTimer(Main.instance, 1L, 1L);
64+
}
65+
66+
public static void runix() {
67+
File c = new File("plugins/TaskScheduler/config.yml");
68+
FileConfiguration cfg = YamlConfiguration.loadConfiguration(c);
69+
for (String lootboxx : cfg.getStringList("Tasks." + k + ".Command")) {
70+
lootboxx = lootboxx.replaceAll("&", "§");
71+
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), lootboxx);
72+
}
73+
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.instance, new Runnable() {
74+
public void run() {
75+
taskAgain();
76+
}
77+
}, 25L);
78+
}
79+
}

0 commit comments

Comments
 (0)