3
0
Fork 0
This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
ThemeParkPlus/src/main/lombok/nl/sbdeveloper/themeparkplus/api/PlusAPI.java
2020-06-01 13:43:13 +02:00

94 lines
2.5 KiB
Java

package nl.sbdeveloper.themeparkplus.api;
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.util.ConfigUtil;
import nl.sbdeveloper.themeparkplus.util.XMaterial;
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;
public class PlusAPI {
private static HashMap<Location, Gate> gates = 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;
}
/**
* 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;
}
}