176 lines
4.6 KiB
Java
176 lines
4.6 KiB
Java
package nl.sbdeveloper.themeparkplus.api;
|
|
|
|
import com.sk89q.worldguard.protection.ApplicableRegionSet;
|
|
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
|
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
|
import me.paradoxpixel.themepark.api.attraction.Attraction;
|
|
import nl.sbdeveloper.themeparkplus.ThemeParkPlus;
|
|
import nl.sbdeveloper.themeparkplus.api.objects.Gate;
|
|
import nl.sbdeveloper.themeparkplus.api.objects.WaitingRow;
|
|
import nl.sbdeveloper.themeparkplus.util.ConfigUtil;
|
|
import nl.sbdeveloper.themeparkplus.util.XMaterial;
|
|
import nl.sbdeveloper.themeparkplus.util.WorldGuardLegacyManager;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
public class PlusAPI {
|
|
private static HashMap<Location, Gate> gates = new HashMap<>();
|
|
private static HashMap<String, WaitingRow> rows = new HashMap<>();
|
|
|
|
/**
|
|
* Add a gate
|
|
*
|
|
* @param gate The gate
|
|
*/
|
|
public static void addGate(Gate gate) {
|
|
gates.put(gate.getLoc(), gate);
|
|
}
|
|
|
|
/**
|
|
* Remove a gate
|
|
*
|
|
* @param gate The gate
|
|
*/
|
|
public static void removeGate(@NotNull Gate gate) {
|
|
gates.remove(gate.getLoc());
|
|
}
|
|
|
|
/**
|
|
* Check if a location is a gate
|
|
*
|
|
* @param loc The location
|
|
* @return true/false
|
|
*/
|
|
public static boolean isGate(Location loc) {
|
|
return gates.containsKey(loc);
|
|
}
|
|
|
|
/**
|
|
* Get a gate by the location
|
|
*
|
|
* @param loc The location
|
|
* @return The gate
|
|
*/
|
|
public static Gate getGate(Location loc) {
|
|
return gates.get(loc);
|
|
}
|
|
|
|
/**
|
|
* Get all the gates
|
|
*
|
|
* @return Map with location and gate
|
|
*/
|
|
public static HashMap<Location, Gate> getGates() {
|
|
return gates;
|
|
}
|
|
|
|
/**
|
|
* Add a row
|
|
*
|
|
* @param row The row
|
|
*/
|
|
public static void addRow(WaitingRow row) {
|
|
rows.put(row.getRideID(), row);
|
|
}
|
|
|
|
/**
|
|
* Remove a row
|
|
*
|
|
* @param row The row
|
|
*/
|
|
public static void removeRow(@NotNull WaitingRow row) {
|
|
rows.remove(row.getRideID());
|
|
}
|
|
|
|
/**
|
|
* Check if a location is a row
|
|
*
|
|
* @param rideID The rideID
|
|
* @return true/false
|
|
*/
|
|
public static boolean isRow(String rideID) {
|
|
return rows.containsKey(rideID);
|
|
}
|
|
|
|
/**
|
|
* Get a row by the rideid
|
|
*
|
|
* @param rideID The rideID
|
|
* @return The row
|
|
*/
|
|
public static WaitingRow getRow(String rideID) {
|
|
return rows.get(rideID);
|
|
}
|
|
|
|
/**
|
|
* Get a row by the location
|
|
*
|
|
* @param loc The location
|
|
* @return The row
|
|
*/
|
|
@Nullable
|
|
public static WaitingRow getRow(Location loc) {
|
|
if (loc == null) return null;
|
|
ApplicableRegionSet set = WorldGuardLegacyManager.getInstance().getApplicableRegionSet(loc);
|
|
for (WaitingRow row : rows.values()) {
|
|
if (set.getRegions().stream().anyMatch(region -> region.getId().equalsIgnoreCase(row.getRegionID()))) {
|
|
return row;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Get a row by the sign location
|
|
*
|
|
* @param signLoc The sign location
|
|
* @return The row
|
|
*/
|
|
@NotNull
|
|
public static Optional<WaitingRow> getRowBySign(Location signLoc) {
|
|
return rows.values().stream().filter(row -> row.getSignLocations().contains(signLoc)).findFirst();
|
|
}
|
|
|
|
/**
|
|
* Get all the rows
|
|
*
|
|
* @return Map with location and rows
|
|
*/
|
|
public static HashMap<String, WaitingRow> getRows() {
|
|
return rows;
|
|
}
|
|
|
|
/**
|
|
* Get the ticket itemstack
|
|
*
|
|
* @param att The attraction
|
|
*
|
|
* @return The ticket as ItemStack
|
|
*/
|
|
@Nullable
|
|
public static ItemStack getFastpassTicket(Attraction att) {
|
|
String ticketName = ConfigUtil.makecolored(ThemeParkPlus.getSConfig().getFile().getString("Fastpass.Item.DisplayName"));
|
|
|
|
ItemStack ticket = XMaterial.PAPER.parseItem();
|
|
if (ticket == null) return null;
|
|
ItemMeta meta = ticket.getItemMeta();
|
|
if (meta == null) return null;
|
|
meta.setDisplayName(ticketName);
|
|
List<String> ticketLores = ConfigUtil.getLore("Fastpass.Item.Lore", Collections.singletonMap("%ridename%", att.getName()));
|
|
meta.setLore(ticketLores);
|
|
ticket.setItemMeta(meta);
|
|
|
|
NBTItem item = new NBTItem(ticket);
|
|
item.setString("RideID", att.getId());
|
|
ticket = item.getItem();
|
|
return ticket;
|
|
}
|
|
}
|