001package com.ericlam.mc.minigames.core.arena; 002 003import com.ericlam.mc.minigames.core.exception.NoMoreElementException; 004import com.ericlam.mc.minigames.core.exception.arena.create.LocationMaxReachedException; 005import com.ericlam.mc.minigames.core.exception.arena.create.NoMoreLocationException; 006import com.ericlam.mc.minigames.core.exception.arena.create.WarpExistException; 007import com.ericlam.mc.minigames.core.exception.arena.create.WarpNotExistException; 008import org.bukkit.Location; 009import org.bukkit.World; 010 011import java.util.LinkedList; 012import java.util.List; 013import java.util.Map; 014import java.util.Optional; 015 016/** 017 * 設置場地接口, 用於設置場地 018 */ 019public interface CreateArena extends Arena { 020 021 /** 022 * @param author 場地作者 023 */ 024 void setAuthor(String author); 025 026 /** 027 * @param world 場地世界 028 */ 029 void setWorld(World world); 030 031 /** 032 * @param arenaName 場地名稱 033 */ 034 void setArenaName(String arenaName); 035 036 /** 037 * @param displayName 場地顯示名稱 038 */ 039 void setDisplayName(String displayName); 040 041 /** 042 * @param warp 地標 043 * @param location 位置 044 * @param max 最大設置數 045 * @throws WarpNotExistException 地標不存在時 046 * @throws LocationMaxReachedException 地標位置數過多時 047 */ 048 default void addLocation(String warp, Location location, final int max) throws WarpNotExistException, LocationMaxReachedException { 049 List<Location> locs = Optional.ofNullable(getWarp(warp)).orElseThrow(() -> new WarpNotExistException(warp)); 050 if (locs.size() >= max) throw new LocationMaxReachedException(warp); 051 locs.add(location); 052 } 053 054 /** 055 * 刪除上一個地標 056 * 057 * @param warp 地標 058 * @throws WarpNotExistException 地標不存在時 059 * @throws NoMoreLocationException 沒有更多位置時 060 */ 061 default void removeLastLocation(String warp) throws WarpNotExistException, NoMoreLocationException { 062 List<Location> locs = Optional.ofNullable(getWarp(warp)).orElseThrow(() -> new WarpNotExistException(warp)); 063 if (locs.size() == 0) throw new NoMoreLocationException(warp); 064 locs.remove(locs.size() - 1); 065 } 066 067 /** 068 * @param warp 添加地標 069 * @throws WarpExistException 地標已存在時 070 */ 071 default void addWarp(String warp) throws WarpExistException { 072 if (getLocationsMap().putIfAbsent(warp, new LinkedList<>()) != null) throw new WarpExistException(warp); 073 } 074 075 /** 076 * @param warp 刪除地標 077 * @throws WarpNotExistException 地標不存在時 078 */ 079 default void removeWarp(String warp) throws WarpNotExistException { 080 if (getLocationsMap().remove(warp) == null) throw new WarpNotExistException(warp); 081 } 082 083 /** 084 * 為描述添加新一行 085 * 086 * @param text 描述文字 087 */ 088 default void addDescriptionLine(String text) { 089 getDescription().add(text); 090 } 091 092 /** 093 * 刪除上一行描述 094 * 095 * @throws NoMoreElementException 沒有更多描述時 096 */ 097 default void removeDescriptionLine() throws NoMoreElementException { 098 if (getDescription().size() == 0) throw new NoMoreElementException(this.getArenaName()); 099 getDescription().remove(getDescription().size() - 1); 100 } 101 102 /** 103 * @param locationMap 地標列表 104 */ 105 void setLocationMap(Map<String, List<Location>> locationMap); 106 107 /** 108 * @return 場地有否被變更 109 */ 110 boolean isChanged(); 111 112 /** 113 * 設置場地有否被變更 114 * 115 * @param changed 有否被變更 116 */ 117 void setChanged(Boolean changed); 118 119 /** 120 * 定義場地完成設置的條件 121 * 122 * @return 是否完成設置 123 */ 124 boolean isSetupCompleted(); 125}