Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package net.tfminecraft.vfbuilders.api;

import java.util.UUID;

/**
* Lets another plugin pause station countdowns. Register an implementation with
* Bukkit's ServicesManager. Each second, registrations are asked in turn for every
* station still counting down, stopping at the first one that returns a reason.
*/
public interface ConstructionFreeze {

/**
* @param constructorUuid player who started the project
* @return why the project is paused, shown under the station timer, or null to keep counting down
*/
String freezeReason(UUID constructorUuid);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.tfminecraft.vfbuilders.api;

import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;

/** Asks every registered {@link ConstructionFreeze} whether a project should hold. */
public final class ConstructionFreezes {

private ConstructionFreezes() {
}

/** @return the first freeze reason for this constructor, or null when nothing pauses it */
public static String reason(UUID constructorUuid) {
if (constructorUuid == null) {
return null;
}
for (RegisteredServiceProvider<ConstructionFreeze> registration
: Bukkit.getServicesManager().getRegistrations(ConstructionFreeze.class)) {
String reason;
try {
reason = registration.getProvider().freezeReason(constructorUuid);
} catch (RuntimeException e) {
// A broken provider must not stall every station on the server.
continue;
}
if (reason != null) {
return reason;
}
}
return null;
}
}
14 changes: 13 additions & 1 deletion src/main/java/net/tfminecraft/vfbuilders/core/ActiveStation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.Sound;
import org.bukkit.entity.TextDisplay;

import net.tfminecraft.vfbuilders.api.ConstructionFreezes;
import net.tfminecraft.vfbuilders.display.StationTimerDisplay;
import net.tfminecraft.vfbuilders.events.VehicleConstructEvent;
import net.tfminecraft.vfbuilders.loaders.BlueprintLoader;
Expand All @@ -28,6 +29,7 @@ public class ActiveStation {
private UUID constructorUuid;

private TextDisplay timerDisplay;
private String freezeReason;


public ActiveStation(Location loc, Station stored) {
Expand Down Expand Up @@ -72,6 +74,7 @@ public void selectBlueprint(Blueprint b, UUID constructorUuid) {
blueprint = b;
timeLeft = b.getTime();
this.constructorUuid = constructorUuid;
freezeReason = null;
ensureDisplay();
}

Expand All @@ -81,6 +84,14 @@ public boolean tick() {
return true;
}

String reason = ConstructionFreezes.reason(constructorUuid);
if (reason != null) {
freezeReason = reason;
ensureDisplay();
return false;
}
freezeReason = null;

timeLeft--;
ensureDisplay();

Expand Down Expand Up @@ -138,6 +149,7 @@ public void cancelConstruction() {
spawnLoc = null;
blueprint = null;
constructorUuid = null;
freezeReason = null;
timeLeft = 0;
}

Expand Down Expand Up @@ -220,7 +232,7 @@ public void ensureDisplay() {
StationTimerDisplay.purgeAtStationBlock(loc);
StationTimerDisplay.purgeLegacyArmorStands(loc);

String text = StationTimerDisplay.formatText(blueprint.getVehicle().getName(), timeLeft);
String text = StationTimerDisplay.formatText(blueprint.getVehicle().getName(), timeLeft, freezeReason);
if (timerDisplay == null || timerDisplay.isDead()) {
timerDisplay = StationTimerDisplay.spawn(loc.getWorld(), loc, text);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@ public static Location displayAnchor(Location stationBlock) {
}

public static String formatText(String vehicleName, int timeLeftSeconds) {
return formatText(vehicleName, timeLeftSeconds, null);
}

public static String formatText(String vehicleName, int timeLeftSeconds, String freezeReason) {
String name = vehicleName == null ? "Vehicle" : vehicleName;
return "搂eConstructing 搂6" + name
String text = "搂eConstructing 搂6" + name
+ "\n搂7Time: 搂f" + TimeFormatter.formatTime(timeLeftSeconds);
if (freezeReason != null) {
text += "\n搂cPaused: 搂7" + freezeReason;
}
return text;
}

public static TextDisplay spawn(World world, Location stationBlock, String text) {
Expand Down