parent
282bebdcdb
commit
6f28250a10
13 changed files with 308 additions and 13 deletions
4
pom.xml
4
pom.xml
|
@ -6,13 +6,11 @@
|
||||||
|
|
||||||
<groupId>eu.m724</groupId>
|
<groupId>eu.m724</groupId>
|
||||||
<artifactId>tweaks</artifactId>
|
<artifactId>tweaks</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>21</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>21</maven.compiler.target>
|
||||||
<timestamp>${maven.build.timestamp}</timestamp>
|
|
||||||
<maven.build.timestamp.format>dd-MM-yyyy</maven.build.timestamp.format>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.spigot.version>1.21.1-R0.1-SNAPSHOT</project.spigot.version>
|
<project.spigot.version>1.21.1-R0.1-SNAPSHOT</project.spigot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -26,7 +26,10 @@ public record TweaksConfig(
|
||||||
|
|
||||||
boolean compassEnabled,
|
boolean compassEnabled,
|
||||||
int compassWidth,
|
int compassWidth,
|
||||||
int compassPrecision
|
int compassPrecision,
|
||||||
|
|
||||||
|
boolean pomodoroEnabled,
|
||||||
|
boolean pomodoroForce
|
||||||
) {
|
) {
|
||||||
public static final int CONFIG_VERSION = 1;
|
public static final int CONFIG_VERSION = 1;
|
||||||
private static TweaksConfig config;
|
private static TweaksConfig config;
|
||||||
|
@ -73,6 +76,9 @@ public record TweaksConfig(
|
||||||
int compassWidth = config.getInt("compass.width");
|
int compassWidth = config.getInt("compass.width");
|
||||||
int compassPrecision = config.getInt("compass.precision");
|
int compassPrecision = config.getInt("compass.precision");
|
||||||
|
|
||||||
|
boolean pomodoroEnabled = config.getBoolean("pomodoro.enabled");
|
||||||
|
boolean pomodoroForce = config.getBoolean("pomodoro.force");
|
||||||
|
|
||||||
TweaksConfig.config = new TweaksConfig(
|
TweaksConfig.config = new TweaksConfig(
|
||||||
isProtocolLib,
|
isProtocolLib,
|
||||||
hideWorldBorder,
|
hideWorldBorder,
|
||||||
|
@ -80,7 +86,8 @@ public record TweaksConfig(
|
||||||
doorEnabled, doorDoubleOpen, doorKnocking,
|
doorEnabled, doorDoubleOpen, doorKnocking,
|
||||||
motdEnabled, motdSet,
|
motdEnabled, motdSet,
|
||||||
chatEnabled, chatLocalEvents, chatDefaultName,
|
chatEnabled, chatLocalEvents, chatDefaultName,
|
||||||
compassEnabled, compassWidth, compassPrecision
|
compassEnabled, compassWidth, compassPrecision,
|
||||||
|
pomodoroEnabled, pomodoroForce
|
||||||
);
|
);
|
||||||
|
|
||||||
return TweaksConfig.config;
|
return TweaksConfig.config;
|
||||||
|
|
|
@ -8,6 +8,8 @@ import eu.m724.tweaks.motd.MotdListener;
|
||||||
import eu.m724.tweaks.ping.F3NameListener;
|
import eu.m724.tweaks.ping.F3NameListener;
|
||||||
import eu.m724.tweaks.ping.PingChecker;
|
import eu.m724.tweaks.ping.PingChecker;
|
||||||
import eu.m724.tweaks.ping.PingCommands;
|
import eu.m724.tweaks.ping.PingCommands;
|
||||||
|
import eu.m724.tweaks.pomodoro.PomodoroCommands;
|
||||||
|
import eu.m724.tweaks.pomodoro.PomodoroManager;
|
||||||
import eu.m724.tweaks.worldborder.WorldBorderManager;
|
import eu.m724.tweaks.worldborder.WorldBorderManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
@ -19,8 +21,6 @@ public class TweaksPlugin extends JavaPlugin {
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
TweaksConfig config = TweaksConfig.load(this);
|
TweaksConfig config = TweaksConfig.load(this);
|
||||||
|
|
||||||
new CompassManager(this).init();
|
|
||||||
|
|
||||||
if (config.chatEnabled()) {
|
if (config.chatEnabled()) {
|
||||||
ChatManager chatManager = new ChatManager(this);
|
ChatManager chatManager = new ChatManager(this);
|
||||||
chatManager.init();
|
chatManager.init();
|
||||||
|
@ -60,5 +60,11 @@ public class TweaksPlugin extends JavaPlugin {
|
||||||
if (config.worldborderHide()) {
|
if (config.worldborderHide()) {
|
||||||
new WorldBorderManager().init(this);
|
new WorldBorderManager().init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.pomodoroEnabled()) {
|
||||||
|
new PomodoroManager(this).init();
|
||||||
|
getCommand("pomodoro").setExecutor(new PomodoroCommands());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ public class ChatManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
|
if (plugin.getServer().isEnforcingSecureProfiles()) {
|
||||||
|
throw new RuntimeException("Please disable enforce-secure-profile in server.properties to use chatrooms");
|
||||||
|
}
|
||||||
|
|
||||||
getById(defaultRoom);
|
getById(defaultRoom);
|
||||||
plugin.getServer().getPluginManager().registerEvents(new ChatListener(this), plugin);
|
plugin.getServer().getPluginManager().registerEvents(new ChatListener(this), plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package eu.m724.tweaks.playtime;
|
|
||||||
|
|
||||||
public class PlaytimeListener {
|
|
||||||
|
|
||||||
}
|
|
68
src/main/java/eu/m724/tweaks/pomodoro/PlayerPomodoro.java
Normal file
68
src/main/java/eu/m724/tweaks/pomodoro/PlayerPomodoro.java
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
public class PlayerPomodoro {
|
||||||
|
private int pomodori = 0;
|
||||||
|
|
||||||
|
private boolean isBreak = false;
|
||||||
|
// this is for both break and not break
|
||||||
|
private long intervalStart = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A "pomodoro" is the 25-minute cycle you take breaks after<br>
|
||||||
|
* This returns how many cycles already elapsed, so if this is the first cycle this is 0<br>
|
||||||
|
* The break after the "pomodoro," so if it's breaktime after the first "pomodoro" it stays at 0
|
||||||
|
*/
|
||||||
|
public int getPomodori() {
|
||||||
|
return pomodori;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When did the current interval start<br>
|
||||||
|
* Or when did the break start
|
||||||
|
*
|
||||||
|
* @see PlayerPomodoro#isBreak()
|
||||||
|
*/
|
||||||
|
public long getIntervalStart() {
|
||||||
|
return intervalStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCycleDurationSeconds() {
|
||||||
|
return isBreak ? 300 : 1500;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRemainingSeconds(long now) {
|
||||||
|
return getCycleDurationSeconds() - (now - getIntervalStart()) / 1000000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is it a break currently
|
||||||
|
*/
|
||||||
|
public boolean isBreak() {
|
||||||
|
return isBreak;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCycleComplete() {
|
||||||
|
return intervalStart + getCycleDurationSeconds() * 1000000000L < System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets and starts the timer
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
this.pomodori = 0;
|
||||||
|
this.isBreak = false;
|
||||||
|
this.intervalStart = System.nanoTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Completes a cycle
|
||||||
|
*/
|
||||||
|
public void next() {
|
||||||
|
if (isBreak) { // from break to interval
|
||||||
|
this.pomodori++;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.intervalStart = System.nanoTime();
|
||||||
|
isBreak = !isBreak;
|
||||||
|
}
|
||||||
|
}
|
43
src/main/java/eu/m724/tweaks/pomodoro/PomodoroCommands.java
Normal file
43
src/main/java/eu/m724/tweaks/pomodoro/PomodoroCommands.java
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ClickEvent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PomodoroCommands implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
String action = args.length > 0 ? args[0] : null;
|
||||||
|
|
||||||
|
PlayerPomodoro pomodoro = Pomodoros.get(player);
|
||||||
|
|
||||||
|
if (pomodoro != null) {
|
||||||
|
if ("stop".equals(action)) {
|
||||||
|
Pomodoros.remove(player);
|
||||||
|
sender.sendMessage("Pomodoro disabled");
|
||||||
|
} else {
|
||||||
|
if (pomodoro.isCycleComplete()) {
|
||||||
|
pomodoro.next();
|
||||||
|
}
|
||||||
|
sender.spigot().sendMessage(Pomodoros.formatTimer(pomodoro, pomodoro.getRemainingSeconds(System.nanoTime())));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ("start".equals(action)) {
|
||||||
|
pomodoro = Pomodoros.create(player);
|
||||||
|
pomodoro.start();
|
||||||
|
sender.spigot().sendMessage(Pomodoros.formatTimer(pomodoro, pomodoro.getCycleDurationSeconds()));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Start pomodoro with /pom start");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
52
src/main/java/eu/m724/tweaks/pomodoro/PomodoroListener.java
Normal file
52
src/main/java/eu/m724/tweaks/pomodoro/PomodoroListener.java
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
|
||||||
|
public class PomodoroListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PlayerPomodoro timer = Pomodoros.get(player);
|
||||||
|
if (timer == null) return;
|
||||||
|
|
||||||
|
if (timer.isBreak()) {
|
||||||
|
if (timer.isCycleComplete()) {
|
||||||
|
timer.next();
|
||||||
|
} else {
|
||||||
|
event.getPlayer().kickPlayer(
|
||||||
|
new ComponentBuilder()
|
||||||
|
.append(Pomodoros.formatTimer(timer, System.nanoTime()))
|
||||||
|
.build().toLegacyText()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PlayerPomodoro timer = Pomodoros.timers.get(player);
|
||||||
|
if (timer == null) return;
|
||||||
|
|
||||||
|
if (!timer.isBreak() && timer.isCycleComplete()) {
|
||||||
|
timer.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
PlayerPomodoro timer = Pomodoros.get(player);
|
||||||
|
if (timer == null) return;
|
||||||
|
|
||||||
|
if (timer.isBreak() && timer.getRemainingSeconds(System.nanoTime()) <= 0)
|
||||||
|
timer.next(); // resume timer if break ended
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/eu/m724/tweaks/pomodoro/PomodoroManager.java
Normal file
17
src/main/java/eu/m724/tweaks/pomodoro/PomodoroManager.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class PomodoroManager {
|
||||||
|
private final Plugin plugin;
|
||||||
|
|
||||||
|
public PomodoroManager(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(new PomodoroListener(), plugin);
|
||||||
|
new PomodoroRunnable().runTaskTimerAsynchronously(plugin, 0, 20L);
|
||||||
|
}
|
||||||
|
}
|
26
src/main/java/eu/m724/tweaks/pomodoro/PomodoroRunnable.java
Normal file
26
src/main/java/eu/m724/tweaks/pomodoro/PomodoroRunnable.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
public class PomodoroRunnable extends BukkitRunnable {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
PlayerPomodoro pomodoro = Pomodoros.get(player);
|
||||||
|
if (pomodoro == null) return;
|
||||||
|
|
||||||
|
long remaining = pomodoro.getRemainingSeconds(now);
|
||||||
|
// TODO make not always on
|
||||||
|
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, Pomodoros.formatTimer(pomodoro, remaining));
|
||||||
|
|
||||||
|
if (remaining <= 0)
|
||||||
|
player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_FALL, 1.0f, 0.5f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
65
src/main/java/eu/m724/tweaks/pomodoro/Pomodoros.java
Normal file
65
src/main/java/eu/m724/tweaks/pomodoro/Pomodoros.java
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package eu.m724.tweaks.pomodoro;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.chat.BaseComponent;
|
||||||
|
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Pomodoros {
|
||||||
|
static final Map<UUID, PlayerPomodoro> timers = new HashMap<>();
|
||||||
|
|
||||||
|
public static PlayerPomodoro get(Player player) {
|
||||||
|
return timers.get(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerPomodoro create(Player player) {
|
||||||
|
return timers.computeIfAbsent(player.getUniqueId(), (k) -> new PlayerPomodoro());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean remove(Player player) {
|
||||||
|
return timers.remove(player.getUniqueId()) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static BaseComponent[] formatTimer(PlayerPomodoro pomodoro, long remaining) {
|
||||||
|
ComponentBuilder builder = new ComponentBuilder();
|
||||||
|
|
||||||
|
if (pomodoro.isBreak()) {
|
||||||
|
builder.append("Break ").color(ChatColor.LIGHT_PURPLE);
|
||||||
|
if (remaining > 0) {
|
||||||
|
builder.append("%02d:%02d".formatted(remaining / 60, remaining % 60))
|
||||||
|
.color(ChatColor.GOLD);
|
||||||
|
} else {
|
||||||
|
builder.append("00:00")
|
||||||
|
.color(ChatColor.GREEN);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (remaining > 0) {
|
||||||
|
builder
|
||||||
|
.append("%02d:%02d".formatted(remaining / 60, remaining % 60))
|
||||||
|
.color(ChatColor.GRAY);
|
||||||
|
} else {
|
||||||
|
builder
|
||||||
|
.append("%02d:%02d".formatted(-remaining / 60, -remaining % 60))
|
||||||
|
.color(remaining % 2 == 0 ? ChatColor.RED : ChatColor.YELLOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i=0; i<4; i++) {
|
||||||
|
ChatColor color = ChatColor.GRAY;
|
||||||
|
if (i == pomodoro.getPomodori()) {
|
||||||
|
color = ChatColor.LIGHT_PURPLE;
|
||||||
|
} else if (i > pomodoro.getPomodori()) {
|
||||||
|
color = ChatColor.DARK_GRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.append(" o").color(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,11 @@ compass:
|
||||||
# How many degrees every point
|
# How many degrees every point
|
||||||
precision: 10
|
precision: 10
|
||||||
|
|
||||||
|
pomodoro:
|
||||||
|
enabled: true
|
||||||
|
# Players will be unable to join the server during break and will be kicked a short time after pomodoro ends
|
||||||
|
force: true
|
||||||
|
|
||||||
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
# Finally, thank you for downloading Tweaks724, I hope you enjoy!
|
||||||
|
|
||||||
# Don't modify unless told to
|
# Don't modify unless told to
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: Tweaks724
|
name: Tweaks724
|
||||||
version: ${project.version}+${timestamp}
|
version: ${project.version}
|
||||||
|
|
||||||
main: eu.m724.tweaks.TweaksPlugin
|
main: eu.m724.tweaks.TweaksPlugin
|
||||||
api-version: 1.21.1
|
api-version: 1.21.1
|
||||||
|
@ -13,14 +13,23 @@ commands:
|
||||||
aliases: [c, chatroom, cr, room]
|
aliases: [c, chatroom, cr, room]
|
||||||
chatmanage:
|
chatmanage:
|
||||||
description: Chatroom user management commands
|
description: Chatroom user management commands
|
||||||
|
permission: tweaks724.chatmanage
|
||||||
aliases: [cm, crm]
|
aliases: [cm, crm]
|
||||||
ping:
|
ping:
|
||||||
description: Your ping
|
description: Your ping
|
||||||
dkick:
|
dkick:
|
||||||
description: Kick a player discreetly
|
description: Kick a player discreetly
|
||||||
permission: tweaks724.dkick
|
permission: tweaks724.dkick
|
||||||
|
pomodoro:
|
||||||
|
description: Pomodoro management
|
||||||
|
permission: tweaks724.pomodoro
|
||||||
|
aliases: [pom]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
|
tweaks724.chatmanage:
|
||||||
|
default: true
|
||||||
tweaks724.dkick:
|
tweaks724.dkick:
|
||||||
default: op
|
default: op
|
||||||
|
tweaks724.pomodoro:
|
||||||
|
default: true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue