Skip to content

Commit

Permalink
chore: run formatter
Browse files Browse the repository at this point in the history
npx prettier --write "**/*.java"
  • Loading branch information
oddlama committed Nov 20, 2024
1 parent dd18b83 commit c3ccea3
Show file tree
Hide file tree
Showing 373 changed files with 30,868 additions and 30,259 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins:
- prettier-plugin-java
useTabs: false
tabWidth: 4
printWidth: 120
29 changes: 15 additions & 14 deletions vane-admin/src/main/java/org/oddlama/vane/admin/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@

@VaneModule(name = "admin", bstats = 8638, config_version = 2, lang_version = 2, storage_version = 1)
public class Admin extends Module<Admin> {
public Admin() {
// Create components
new org.oddlama.vane.admin.commands.Gamemode(this);
new org.oddlama.vane.admin.commands.SlimeChunk(this);
new org.oddlama.vane.admin.commands.Time(this);
new org.oddlama.vane.admin.commands.Weather(this);

var autostop_group = new AutostopGroup(this);
new AutostopListener(autostop_group);
new org.oddlama.vane.admin.commands.Autostop(autostop_group);
public Admin() {
// Create components
new org.oddlama.vane.admin.commands.Gamemode(this);
new org.oddlama.vane.admin.commands.SlimeChunk(this);
new org.oddlama.vane.admin.commands.Time(this);
new org.oddlama.vane.admin.commands.Weather(this);

new SpawnProtection(this);
new WorldProtection(this);
new HazardProtection(this);
new ChatMessageFormatter(this);
}
var autostop_group = new AutostopGroup(this);
new AutostopListener(autostop_group);
new org.oddlama.vane.admin.commands.Autostop(autostop_group);

new SpawnProtection(this);
new WorldProtection(this);
new HazardProtection(this);
new ChatMessageFormatter(this);
}
}
193 changes: 95 additions & 98 deletions vane-admin/src/main/java/org/oddlama/vane/admin/AutostopGroup.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.oddlama.vane.admin;

import static org.oddlama.vane.util.TimeUtil.format_time;
import static org.oddlama.vane.util.Conversions.ms_to_ticks;
import static org.oddlama.vane.util.TimeUtil.format_time;

import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask;
Expand All @@ -13,101 +13,98 @@

public class AutostopGroup extends ModuleGroup<Admin> {

@ConfigLong(def = 20 * 60, min = 0, desc = "Delay in seconds after which to stop the server.")
public long config_delay;

@LangMessage
public TranslatedMessage lang_aborted;

@LangMessage
public TranslatedMessage lang_scheduled;

@LangMessage
public TranslatedMessage lang_status;

@LangMessage
public TranslatedMessage lang_status_not_scheduled;

@LangMessage
public TranslatedMessage lang_shutdown;

// Variables
public BukkitTask task = null;
public long start_time = -1;
public long stop_time = -1;

public AutostopGroup(Context<Admin> context) {
super(context, "autostop", "Enable automatic server stop after certain time without online players.");
}

public long remaining() {

if (start_time == -1) {
return -1;
}

return stop_time - System.currentTimeMillis();

}

public void abort() {
abort(null);
}

public void abort(CommandSender sender) {
if (task == null) {
lang_status_not_scheduled.send(sender);
return;
}

task.cancel();
task = null;
start_time = -1;
stop_time = -1;

lang_aborted.send_and_log(sender);
}

public void schedule() {
schedule(null);
}

public void schedule(CommandSender sender) {
schedule(sender, config_delay * 1000);
}

public void schedule(CommandSender sender, long delay) {
if (task != null) {
abort(sender);
}

start_time = System.currentTimeMillis();
stop_time = start_time + delay;
task =
schedule_task(
() -> {
lang_shutdown.send_and_log(null);
get_module().getServer().shutdown();
},
ms_to_ticks(delay)
);

lang_scheduled.send_and_log(sender, "§b" + format_time(delay));
}

public void status(CommandSender sender) {
if (task == null) {
lang_status_not_scheduled.send(sender);
return;
}

lang_status.send(sender, "§b" + format_time(remaining()));
}

@Override
public void on_enable() {
if (get_module().getServer().getOnlinePlayers().isEmpty()) {
schedule();
}
}
@ConfigLong(def = 20 * 60, min = 0, desc = "Delay in seconds after which to stop the server.")
public long config_delay;

@LangMessage
public TranslatedMessage lang_aborted;

@LangMessage
public TranslatedMessage lang_scheduled;

@LangMessage
public TranslatedMessage lang_status;

@LangMessage
public TranslatedMessage lang_status_not_scheduled;

@LangMessage
public TranslatedMessage lang_shutdown;

// Variables
public BukkitTask task = null;
public long start_time = -1;
public long stop_time = -1;

public AutostopGroup(Context<Admin> context) {
super(context, "autostop", "Enable automatic server stop after certain time without online players.");
}

public long remaining() {
if (start_time == -1) {
return -1;
}

return stop_time - System.currentTimeMillis();
}

public void abort() {
abort(null);
}

public void abort(CommandSender sender) {
if (task == null) {
lang_status_not_scheduled.send(sender);
return;
}

task.cancel();
task = null;
start_time = -1;
stop_time = -1;

lang_aborted.send_and_log(sender);
}

public void schedule() {
schedule(null);
}

public void schedule(CommandSender sender) {
schedule(sender, config_delay * 1000);
}

public void schedule(CommandSender sender, long delay) {
if (task != null) {
abort(sender);
}

start_time = System.currentTimeMillis();
stop_time = start_time + delay;
task = schedule_task(
() -> {
lang_shutdown.send_and_log(null);
get_module().getServer().shutdown();
},
ms_to_ticks(delay)
);

lang_scheduled.send_and_log(sender, "§b" + format_time(delay));
}

public void status(CommandSender sender) {
if (task == null) {
lang_status_not_scheduled.send(sender);
return;
}

lang_status.send(sender, "§b" + format_time(remaining()));
}

@Override
public void on_enable() {
if (get_module().getServer().getOnlinePlayers().isEmpty()) {
schedule();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@

public class AutostopListener extends Listener<Admin> {

AutostopGroup autostop;

public AutostopListener(AutostopGroup context) {
super(context);
this.autostop = context;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_join(PlayerJoinEvent event) {
autostop.abort();
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_kick(PlayerKickEvent event) {
player_leave(event.getPlayer());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_quit(PlayerQuitEvent event) {
player_leave(event.getPlayer());
}

private void player_leave(final Player player) {
var players = get_module().getServer().getOnlinePlayers();
if (players.isEmpty() || (players.size() == 1 && players.iterator().next() == player)) {
autostop.schedule();
}
}
AutostopGroup autostop;

public AutostopListener(AutostopGroup context) {
super(context);
this.autostop = context;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_join(PlayerJoinEvent event) {
autostop.abort();
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_kick(PlayerKickEvent event) {
player_leave(event.getPlayer());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on_player_quit(PlayerQuitEvent event) {
player_leave(event.getPlayer());
}

private void player_leave(final Player player) {
var players = get_module().getServer().getOnlinePlayers();
if (players.isEmpty() || (players.size() == 1 && players.iterator().next() == player)) {
autostop.schedule();
}
}
}
Loading

0 comments on commit c3ccea3

Please sign in to comment.