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
Expand Up @@ -11,6 +11,7 @@
import net.tfminecraft.vfbuilders.api.ConstructionFreezes;
import net.tfminecraft.vfbuilders.display.StationTimerDisplay;
import net.tfminecraft.vfbuilders.events.VehicleConstructEvent;
import net.tfminecraft.vfbuilders.events.VehicleConstructionCancelEvent;
import net.tfminecraft.vfbuilders.loaders.BlueprintLoader;
import net.tfminecraft.vfbuilders.loaders.StationLoader;
import net.tfminecraft.vehicleframework.VFLogger;
Expand Down Expand Up @@ -144,6 +145,8 @@ public void complete() {
public void cancelConstruction() {
if (blueprint != null) {
blueprint.drop(loc.clone().add(0.5, 1, 0.5));
Bukkit.getPluginManager().callEvent(
new VehicleConstructionCancelEvent(constructorUuid, blueprint, this));
}
removeHolograms();
spawnLoc = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class BeginVehicleConstructionEvent extends Event implements Cancellable
private final ActiveStation station;
private final Location spawnLocation;
private boolean cancelled;
private boolean keepPlacement;

public BeginVehicleConstructionEvent(
Player constructor,
Expand Down Expand Up @@ -56,6 +57,19 @@ public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

/**
* Whether a cancelled event leaves the player's placement active, so another
* left-click within the placement window fires this event again. Listeners use
* this to ask for a confirming second click.
*/
public boolean isKeepPlacement() {
return keepPlacement;
}

public void setKeepPlacement(boolean keepPlacement) {
this.keepPlacement = keepPlacement;
}

@Override
public HandlerList getHandlers() {
return HANDLERS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package net.tfminecraft.vfbuilders.events;

import java.util.UUID;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

import net.tfminecraft.vfbuilders.core.ActiveStation;
import net.tfminecraft.vfbuilders.core.Blueprint;

/**
* Fired when a started construction is abandoned, after its materials are dropped back
* at the station (the station was removed, or its blueprint disappeared on reload).
*/
public class VehicleConstructionCancelEvent extends Event {
private static final HandlerList HANDLERS = new HandlerList();

private final UUID constructorUuid;
private final Blueprint blueprint;
private final ActiveStation station;

public VehicleConstructionCancelEvent(UUID constructorUuid, Blueprint blueprint, ActiveStation station) {
this.constructorUuid = constructorUuid;
this.blueprint = blueprint;
this.station = station;
}

/** Null for constructions saved before the constructor was recorded. */
public UUID getConstructorUuid() {
return constructorUuid;
}

public Blueprint getBlueprint() {
return blueprint;
}

public ActiveStation getStation() {
return station;
}

@Override
public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

Expand All @@ -15,7 +16,8 @@
import net.tfminecraft.vfbuilders.core.BlueprintCategory;

public class CategoryLoader implements LoaderInterface{
public static HashMap<String, BlueprintCategory> map = new HashMap<>();
// Linked so menus list categories in config order.
public static HashMap<String, BlueprintCategory> map = new LinkedHashMap<>();

public static HashMap<String, BlueprintCategory> get(){
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ public void onPlayerLeftClick(PlayerInteractEvent e) {
p, blueprint, station, clickLoc);
Bukkit.getPluginManager().callEvent(beginEvent);
if (beginEvent.isCancelled()) {
activePlacements.remove(uuid);
if (!beginEvent.isKeepPlacement()) {
activePlacements.remove(uuid);
}
return;
}

Expand Down