> For the complete documentation index, see [llms.txt](https://molasheyu.gitbook.io/realisticseasons-wiki-chinese/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://molasheyu.gitbook.io/realisticseasons-wiki-chinese/kai-fa-zhe/api.md).

# API

API 为开发者提供了许多与 Rs 进行交互的方式,\
你可以通过直接导入 jar包 将 RealisticSeasons API 导入到你的项目中.\
暂未完成 Maven 的支持,请不要忘记在你的 plugin.yml 中将 RealisticSeasons 添加为（软）依赖项

### Methods

`SeasonsAPI seasonsapi = SeasonsAPI.getInstance();`

获取 SeasonsAPI 的一个实例

`seasonsapi.setSeason(World w, Season s);`\
`seasonsapi.setSeason(p.getWorld(), Season.WINTER);`

更改世界中的季节,同时也更新日期

`Season season = seasonsapi.getSeason(World w);`

获取世界的当前季节

`seasonsapi.setDate(World w, Date date);`\
`seasonsapi.setDate(p.getWorld(), new Date(1, 1, 2022));`

更改世界中的日期,同时也可能更新季节，\
请确保导入的是 Rs 提供的的 `Date` 对象而不是 Java 的 `Date` 对象

`Date date = seasonsapi.getDate(World w);`

获取世界的当前日期

`int temperature = seasonsapi.getTemperature(Player p);`

获取玩家的温度

`int airtemperature = seasonsapi.getAirTemperature(Location loc);`

获取所处位置的空气温度

`seasonsapi.applyTimedTemperatureEffect(Player p, int modifier, int seconds);`

向玩家应用临时温度效果, `modifier` 为玩家温度变化量

`TemperatureEffect effect = seasonsapi.applyPermanentTemperatureEffect(Player p, int modifier);`

向玩家应用 `“永久”` 温度效果,该效果不会被自动移除，除非在代码中移除，但在服务器重启后效果会自动失效

`effect.cancel();`

取消温度效果

`int seconds = seasonsapi.getSeconds(World w);` \
`int minutes = seasonsapi.getMinutes(World w);` \
`int hours = seasonsapi.getHours(World w);`

获取世界的时间信息（秒，分，时）

`String dayOfWeek = seasonsapi.getDayOfWeek(World w)`

获取一周中的某一天的名称（名称取决于 `日历系统` 中的设置）

`String monthName = seasonsapi.getCurrentMonthName(World w)`

获取月份的名称（名称取决于 `日历系统` 中的设置）

`SeasonBiome biome = getReplacementSeasonBiome(String biomeName, Season s) SeasonBiome biome =  getReplacementSeasonBiome(Location l, Season s) SeasonBiome biome = getReplacementSeasonBiome(Biome b, Season s)`\
`String hex = biome.getFogColor()`\
`String hex = biome.getWaterColor()`\
`String hex = biome.getWaterFogColor()`\
`String hex = biome.getSkyColor()`\
`String hex = biome.getFoliageColor()`\
`String hex = biome.getGrassColor()`

获取生物群系或位置的季节着色信息(格式为：十六进制)

### Events

```yaml
@EventHandler
 public void onSeasonChange(SeasonChangeEvent e) {
     Season newSeason = e.getNewSeason();
     Season oldSeason = e.getOldSeason();
     World w = e.getWorld();
     // 事件可被取消
     e.setCancelled(true);
 }
```

```yaml
@EventHandler
 public void dayChange(DayChangeEvent e) {
     Date from = e.getFrom();
     Date to = e.getTo();
     World w = e.getWorld();
 }
```

```yaml
@EventHandler
 public void particleStart(SeasonParticleStartEvent e) {
     Player p = e.getPlayer();
     Location loc = e.getLocation();
     SeasonParticle particle = e.getParticleType();
     // 事件可被取消
     e.setCancelled(true);
 }


SeasonParticle enum:
enum SeasonParticle {
    FIREFLY,
    SHOOTING_STAR,
    FALLING_LEAF,
    SMALL_FALLING_LEAF,
    COLD_BREATH
}


```

```yaml
@EventHandler
 public void onSeasonEventStart(SeasonEventStart e) {
     World w = e.getWorld();
     SeasonCustomEvent customEvent = e.getCustomEvent();
     List<String> commands = customEvent.getCommands(true);
     boolean displayInEventList = customEvent.doDisplay();
     String displayName = customEvent.getName();
     
     // 事件可被取消
     e.setCancelled(true);
 }
```

```yaml
@EventHandler
 public void onSeasonEventEnd(SeasonEventEnd e) {
     World w = e.getWorld();
     SeasonCustomEvent customEvent = e.getCustomEvent();
     List<String> commands = customEvent.getCommands(false);
     boolean displayInEventList = customEvent.doDisplay();
     String displayName = customEvent.getName();
 }
```
