From 96acebae7d74b1c76733e9e167acfbeb63c623b5 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sun, 21 Jul 2024 21:38:48 -0700 Subject: [PATCH] Admin script to manage clover --- .../mapstuff/spawner/CloverSpawner.java | 3 - .../stendhal/server/script/ManageClover.java | 78 +++++++++++++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/games/stendhal/server/script/ManageClover.java diff --git a/src/games/stendhal/server/entity/mapstuff/spawner/CloverSpawner.java b/src/games/stendhal/server/entity/mapstuff/spawner/CloverSpawner.java index ebcc8585e2..64669e96d1 100644 --- a/src/games/stendhal/server/entity/mapstuff/spawner/CloverSpawner.java +++ b/src/games/stendhal/server/entity/mapstuff/spawner/CloverSpawner.java @@ -28,9 +28,6 @@ /** * Manages four-leaf clover spawning. - * - * TODO: - * - create script to get location of & manage spawned clover */ public class CloverSpawner extends PassiveEntityRespawnPoint { diff --git a/src/games/stendhal/server/script/ManageClover.java b/src/games/stendhal/server/script/ManageClover.java new file mode 100644 index 0000000000..dd5ac1ba1f --- /dev/null +++ b/src/games/stendhal/server/script/ManageClover.java @@ -0,0 +1,78 @@ +/*************************************************************************** + * Copyright © 2024 - Faiumoni e. V. * + *************************************************************************** + *************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +package games.stendhal.server.script; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import games.stendhal.common.NotificationType; +import games.stendhal.server.core.engine.StendhalRPZone; +import games.stendhal.server.core.scripting.AbstractAdminScript; +import games.stendhal.server.entity.mapstuff.spawner.CloverSpawner; +import games.stendhal.server.util.TimeUtil; + + +/** + * Locates or re-spawns four-leaf clover. + */ +public class ManageClover extends AbstractAdminScript { + + @Override + protected void run(List args) { + final String command = args.get(0).toLowerCase(Locale.ENGLISH); + final CloverSpawner spawner = CloverSpawner.get(); + // re-spawn is always set to midnight + final String timeToRespawn = TimeUtil.timeUntil(TimeUtil.secondsToMidnight()); + if ("status".equals(command)) { + String zoneDesc = "not found"; + final StendhalRPZone zone = spawner.getZone(); + if (zone != null) { + zoneDesc = zone.getName() + " at " + spawner.getX() + "," + spawner.getY(); + } + final boolean available = spawner.hasPickableClover(); + admin.sendPrivateText("Location: " + zoneDesc + "\nClover available: " + + (available ? "yes" : "no") + "\nRespawns in " + timeToRespawn); + } else if ("respawn".equals(command)) { + spawner.onTurnReached(0); + final StendhalRPZone zone = spawner.getZone(); + if (spawner.hasPickableClover() && zone != null) { + admin.sendPrivateText("Spawned clover on " + zone.getName() + " at " + spawner.getX() + "," + + spawner.getY() + "\nRespawns in " + timeToRespawn); + } else { + admin.sendPrivateText(NotificationType.ERROR, + "Failed to spawn clover, will retry in 15 minutes"); + } + } else { + // show unmodified command + admin.sendPrivateText(NotificationType.ERROR, "Unknown command \"" + args.get(0) + "\""); + } + } + + @Override + public int getMinParams() { + return 1; + } + + @Override + public int getMaxParams() { + return 1; + } + + @Override + protected List getParamDetails() { + return Arrays.asList( + "status: Retrieves spawner location and clover availability.", + "respawn: Forces clover to respawn immediately in random location." + ); + } +}