001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package net.tridentsdk.meta.item; 018 019import java.util.Arrays; 020import java.util.List; 021 022import com.google.common.collect.Lists; 023 024/** 025 * Represents the display properties of an Item 026 */ 027public interface ItemDisplayProperties { 028 /** 029 * Returns display name of the item, {@code null} if non-existent. 030 * 031 * @return The display name of the item. 032 */ 033 String displayName(); 034 035 /** 036 * Sets the display name. 037 * 038 * @param displayName 039 * Display name you wish to set the item to. 040 */ 041 void setDisplayName(String displayName); 042 043 /** 044 * Returns lore of the item, {@code null} if non-existent. 045 * 046 * @return The lore of the item. 047 */ 048 List<String> lore(); 049 050 /** 051 * Sets the lore of the item. 052 * 053 * @param lore 054 * Lore you wish to set the item to. 055 */ 056 void setLore(List<String> lore); 057 058 /** 059 * Set the lore of the item. 060 * 061 * @param lore 062 * Lore you wish to set it to. 063 */ 064 default void setLore(String... lore) { 065 this.setLore(Arrays.asList(lore)); 066 } 067 068 /** 069 * Adds lore to the item starting from a specific index. 070 * 071 * @param index 072 * Index to begin insertion at. 073 * @param lore 074 * Lore to be added. 075 * 076 * @see #addLore(String...) 077 */ 078 default void addLore(int index, String... lore) { 079 List<String> curr = this.lore(); 080 if (curr == null) { 081 curr = Lists.newArrayList(); 082 } 083 if (curr.isEmpty()) { 084 curr.addAll(Arrays.asList(lore)); 085 } else { 086 curr.addAll(index, Arrays.asList(lore)); 087 } 088 this.setLore(curr); 089 } 090 091 /** 092 * Appends lore to the item. 093 * 094 * @param lore 095 * Lore to be appended. 096 * 097 * @see #addLore(int, String...) 098 */ 099 default void addLore(String... lore) { 100 this.addLore(this.lore().size(), lore); 101 } 102}