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 @@ -30,6 +30,7 @@
import net.tfminecraft.vehicleframework.vehicles.component.Wings;
import net.tfminecraft.vehicleframework.vehicles.handlers.container.Container;
import net.tfminecraft.vehicleframework.vehicles.handlers.SkinHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.VehicleIcon;
import net.tfminecraft.vehicleframework.vehicles.handlers.skins.VehicleSkin;
import net.tfminecraft.vehicleframework.vehicles.seat.Seat;
import net.tfminecraft.vehicleframework.weapons.ActiveWeapon;
Expand All @@ -41,18 +42,22 @@ public class InventoryManager {
// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
public void seatSelection(Inventory i, Player p, ActiveVehicle v, boolean open) {
int size = Math.max(27, ((v.getSeatHandler().getSeats().size() + 10) / 9) * 9);
VehicleIcon icon = v.getIcon();
// Slots 25 and 26 hold the ownership and dismount controls; slot 24 shows the vehicle when it has an icon.
int firstControl = icon == null ? 25 : 24;
int size = Math.max(27, ((v.getSeatHandler().getSeats().size() + 27 - firstControl + 8) / 9) * 9);
if(open || i.getSize() < size) {
i = VehicleFramework.plugin.getServer().createInventory(new VFInventoryHolder(v.getUUID(), VFGUI.SEAT_SELECTION), size, "§7Select Seat");
open = true;
}
i.clear();
int x = 0;
for(Seat seat : v.getSeatHandler().getSeats()) {
if(x == 25) x += 2; // ownership and dismount controls
if(x == firstControl) x = 27;
i.setItem(x, getSeatItem(v, seat));
x++;
}
if(icon != null) i.setItem(24, createVehicleInfo(v, icon));
// Slot 25 – ownership settings button (owner, or staff on an owned vehicle)
if(OwnershipActions.mayOpenMenu(p, v)) {
i.setItem(25, ownershipGUI.createOwnershipButton());
Expand Down Expand Up @@ -119,6 +124,18 @@ private ItemStack getSeatItem(ActiveVehicle v, Seat s) {
}
// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
private ItemStack createVehicleInfo(ActiveVehicle v, VehicleIcon icon) {
ItemStack i = icon.createItem();
ItemMeta m = i.getItemMeta();
m.setDisplayName(v.getName());
List<String> lore = new ArrayList<>();
lore.add("§7Type: §e"+Text.capitalize(v.getId().replace("_", " ")));
m.setLore(lore);
i.setItemMeta(m);
return i;
}
// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
private ItemStack createDismountButton() {
ItemStack i = new ItemStack(Material.BARRIER, 1);
ItemMeta m = i.getItemMeta();
Expand All @@ -139,7 +156,7 @@ public void repairWindow(Inventory i, Player p, ActiveVehicle v, boolean open, S
int x = 0;
for(VehicleComponent c : v.getComponents()) {
while(locked.contains(x)) x++;
i.setItem(x, getComponentItem(c));
i.setItem(x, getComponentItem(v, c));
x++;
}
for(ActiveWeapon weapon : v.getWeaponHandler().getWeapons()) {
Expand Down Expand Up @@ -216,11 +233,15 @@ private ItemStack getWaterItem(String tool) {
return i;
}
@SuppressWarnings("deprecation")
private ItemStack getComponentItem(VehicleComponent c) {
private ItemStack getComponentItem(ActiveVehicle v, VehicleComponent c) {
ItemStack i = new ItemStack(Material.GREEN_CONCRETE, 1);
String type = "none";
if(c instanceof Hull) {
i.setType(Material.NETHERITE_BLOCK);
if(v.getIcon() != null) {
i = v.getIcon().createItem();
} else {
i.setType(Material.NETHERITE_BLOCK);
}
type = "hull";
} else if(c instanceof Engine) {
i.setType(Material.BLAST_FURNACE);
Expand Down Expand Up @@ -290,7 +311,7 @@ public void skinSelection(Inventory i, Player p, ActiveVehicle v, boolean open)
if (!SkinHandler.isModelAvailable(skin) && !skin.getId().equalsIgnoreCase(currentId)) {
continue;
}
i.setItem(x, getSkinItem(skin, currentId));
i.setItem(x, getSkinItem(skin, currentId, v.getIcon()));
x++;
}
//i.setItem(26, createDismountButton());
Expand All @@ -312,17 +333,27 @@ public void skinSelection(Inventory i, Player p, ActiveVehicle v, boolean open)

// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
private ItemStack getSkinItem(VehicleSkin s, String active) {
ItemStack i = new ItemStack(Material.GREEN_CONCRETE, 1);
if(s.getId().equalsIgnoreCase(active)) {
i = new ItemStack(Material.YELLOW_CONCRETE, 1);
private ItemStack getSkinItem(VehicleSkin s, String active, VehicleIcon icon) {
boolean current = s.getId().equalsIgnoreCase(active);
ItemStack i;
if(icon != null) {
i = icon.createItem();
} else {
i = new ItemStack(current ? Material.YELLOW_CONCRETE : Material.GREEN_CONCRETE, 1);
}
ItemMeta m = i.getItemMeta();
if(s.getId().equalsIgnoreCase(active)) {
if(current) {
m.setDisplayName("§e"+s.getName());
} else {
m.setDisplayName("§a"+s.getName());
}
if(current && icon != null) {
m.addEnchant(Enchantment.UNBREAKING, 1, true);
m.addItemFlags(ItemFlag.HIDE_ENCHANTS);
List<String> lore = new ArrayList<>();
lore.add("§eCurrent skin");
m.setLore(lore);
}
NamespacedKey key = new NamespacedKey(VehicleFramework.plugin, "vf_skin_id");
m.getPersistentDataContainer().set(key, PersistentDataType.STRING, s.getId());
i.setItemMeta(m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class OwnershipGUIManager {
public static final int PICKER_TYPED_SLOT = 25;
public static final int BACK_SLOT = 26;
public static final int OWNER_SLOT = 22;
/** Shows the vehicle when it has an icon; clicking it does nothing. */
public static final int VEHICLE_SLOT = 18;
/** The first group switch; the others follow every second slot in {@link AccessGroup} order. */
public static final int FIRST_GROUP_SLOT = 10;

Expand Down Expand Up @@ -92,6 +94,9 @@ public void ownershipGui(Inventory i, Player p, ActiveVehicle v, boolean open) {
}
}
}
if (v.getIcon() != null) {
i.setItem(VEHICLE_SLOT, createVehicleInfo(v));
}
if (OwnershipMode.characters()) {
i.setItem(OWNER_SLOT, createOwnerInfo(v.getOwnerData().getOwner(), Permissions.isAdmin(p)));
}
Expand Down Expand Up @@ -329,6 +334,16 @@ private ItemStack createCandidate(String name) {
return i;
}

// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
private ItemStack createVehicleInfo(ActiveVehicle v) {
ItemStack i = v.getIcon().createItem();
ItemMeta m = i.getItemMeta();
m.setDisplayName(v.getName());
i.setItemMeta(m);
return i;
}

private ItemStack createOwnerInfo(String owner, boolean staff) {
return createInfo(Material.NAME_TAG, "§7Owner: §f" + OwnerNames.owner(owner, staff), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,12 +1178,12 @@ public void skinSelect(InventoryClickEvent e) {
return;
}

if(i.getType().equals(Material.YELLOW_CONCRETE)) {
NamespacedKey key = new NamespacedKey(VehicleFramework.plugin, "vf_skin_id");
String skinId = i.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
if (skinId != null && skinId.equalsIgnoreCase(v.getSkinHandler().getCurrentSkin().getId())) {
p.sendMessage("§cAlready using this skin");
return;
}
NamespacedKey key = new NamespacedKey(VehicleFramework.plugin, "vf_skin_id");
String skinId = i.getItemMeta().getPersistentDataContainer().get(key, PersistentDataType.STRING);
if (skinId == null || !SkinHandler.isModelAvailable(v.getSkinHandler().getSkins().get(skinId))) {
p.sendMessage("§cThat skin is not available.");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import net.tfminecraft.vehicleframework.vehicles.handlers.TrainHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.train.ConsistRelinker;
import net.tfminecraft.vehicleframework.vehicles.handlers.UtilityHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.VehicleIcon;
import net.tfminecraft.vehicleframework.vehicles.handlers.WeaponHandler;
import net.tfminecraft.vehicleframework.vehicles.seat.Seat;
import net.tfminecraft.vehicleframework.vehicles.state.VehicleState;
Expand All @@ -83,6 +84,7 @@ public class ActiveVehicle {
protected String id;
protected String uuid;
protected String name;
protected VehicleIcon icon;

protected boolean fixed;

Expand Down Expand Up @@ -154,6 +156,7 @@ public ActiveVehicle(Vehicle stored, Entity e, ActiveModel m, VehicleManager man
towable = stored.isTowable();
id = stored.getId();
name = stored.getName();
icon = stored.getIcon();
uuid = UUID.randomUUID().toString();
destroyed = false;
initialized = false;
Expand Down Expand Up @@ -321,6 +324,11 @@ public ContainerHandler getContainerHandler() {
public List<String> getEntitySeatWhitelist() {
return entitySeatWhitelist;
}

/** The vehicle's menu and ticket icon, or null when its config has none. */
public VehicleIcon getIcon() {
return icon;
}

//Model
public boolean changeSkin(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.tfminecraft.vehicleframework.vehicles.handlers.StateHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.TowHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.UtilityHandler;
import net.tfminecraft.vehicleframework.vehicles.handlers.VehicleIcon;
import net.tfminecraft.vehicleframework.vehicles.handlers.container.ContainerHandler;
import net.tfminecraft.vehicleframework.loaders.DeathTemplateLoader;
import net.tfminecraft.vehicleframework.loaders.WeaponTemplateLoader;
Expand All @@ -32,6 +33,9 @@ public class Vehicle {
protected String name;
protected String model;

//Menu and ticket icon, null when the config has none
protected VehicleIcon icon;

protected boolean fixed;

protected boolean towable;
Expand Down Expand Up @@ -85,6 +89,7 @@ public Vehicle(String key, ConfigurationSection config) {
towable = config.getBoolean("towable", false);
if(!config.contains("model")) VFLogger.log(key+" does not contain a model field");
model = config.getString("model");
if(config.contains("icon")) icon = VehicleIcon.load(key, config.getConfigurationSection("icon"));
skinHandler = new SkinHandler(model, config.getConfigurationSection("skins"));

stateHandler = new StateHandler(config.getConfigurationSection("states"));
Expand Down Expand Up @@ -170,6 +175,10 @@ public String getModel() {
return model;
}

public VehicleIcon getIcon() {
return icon;
}

public boolean isFixed() {
return fixed;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.tfminecraft.vehicleframework.vehicles.handlers;

import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import net.tfminecraft.vehicleframework.VFLogger;
import net.tfminecraft.vehicleframework.util.LegacyModelData;

/** The item a vehicle shows in its menus and on its tickets, from the vehicle's {@code icon} section. */
public final class VehicleIcon {
private final Material material;
private final Integer modelData;

public VehicleIcon(Material material, Integer modelData) {
this.material = material;
this.modelData = modelData;
}

/** The icon in a vehicle's {@code icon} section, or null when the section has no known material. */
public static VehicleIcon load(String vehicle, ConfigurationSection config) {
String name = config == null ? null : config.getString("material");
Material material = name == null ? null : Material.matchMaterial(name.trim());
if (material == null) {
VFLogger.log(vehicle + " has an icon without a known material: " + name);
return null;
}
Integer modelData = config.contains("model_data") ? config.getInt("model_data") : null;
return new VehicleIcon(material, modelData);
}

public Material getMaterial() {
return material;
}

/** The custom model data, or null when the icon is the plain material. */
public Integer getModelData() {
return modelData;
}

/** A new single item that looks like this icon. */
public ItemStack createItem() {
ItemStack item = new ItemStack(material, 1);
if (modelData != null) {
ItemMeta meta = item.getItemMeta();
LegacyModelData.set(meta, modelData);
item.setItemMeta(meta);
}
return item;
}

/** Makes an item of any type render as this icon. */
public void applyModel(ItemMeta meta) {
meta.setItemModel(material.getKey());
LegacyModelData.set(meta, modelData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ private static boolean canMint(Player player, ActiveVehicle vehicle) {
private static void mintOne(Player player, ItemStack hand, ActiveVehicle source) {
String ticketId = source.getOwnerData().getTicketId();
String name = source.getName();
VehicleIcon icon = source.getIcon();
if (hand.getAmount() <= 1) {
VehicleTicketItems.write(hand, ticketId, name);
VehicleTicketItems.write(hand, ticketId, name, icon);
return;
}
hand.setAmount(hand.getAmount() - 1);
ItemStack ticket = hand.clone();
ticket.setAmount(1);
VehicleTicketItems.write(ticket, ticketId, name);
VehicleTicketItems.write(ticket, ticketId, name, icon);
PlayerInventory inv = player.getInventory();
java.util.HashMap<Integer, ItemStack> leftover = inv.addItem(ticket);
if (!leftover.isEmpty() && player.getWorld() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static String readId(ItemStack item) {

// Keep the existing legacy text representation, formatting, and exact-string comparisons.
@SuppressWarnings("deprecation")
public static void write(ItemStack item, String ticketId, String vehicleName) {
public static void write(ItemStack item, String ticketId, String vehicleName, VehicleIcon icon) {
if (item == null || ticketId == null || ticketId.isBlank()) {
return;
}
Expand All @@ -49,6 +49,10 @@ public static void write(ItemStack item, String ticketId, String vehicleName) {
List<String> lore = new ArrayList<>();
lore.add("§7Valid for this vehicle");
meta.setLore(lore);
// The ticket looks like the vehicle it admits to.
if (icon != null) {
icon.applyModel(meta);
}
item.setItemMeta(meta);
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/vehicles/aa_turret.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
aa_turret:
name: "§l§eAnti-Air Turret"
model: aa_turret
icon:
material: coal
model_data: 7400
fixed: true
skins:
aa_turret:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/vehicles/anti_air.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
anti_air:
name: "§l§eAnti-Air"
model: anti_air
icon:
material: coal
model_data: 7401
fixed: true
skins:
anti_air:
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/vehicles/behemoth.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
behemoth:
name: "§l§eBehemoth"
model: behemoth
icon:
material: coal
model_data: 7402
skins:
behemoth:
name: "Behemoth"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/vehicles/biplane.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
biplane:
name: "§l§eBiplane"
model: biplane
icon:
material: coal
model_data: 7403
skins:
biplane:
name: "Biplane"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/vehicles/bomber.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
bomber:
name: "§l§eBomber"
model: bomber
icon:
material: coal
model_data: 7404
skins:
bomber:
name: "Bomber"
Expand Down
Loading
Loading