Skip to content

Commit

Permalink
Merge pull request #2 from Vulpeus-Server/feature/loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
hu-ja-ja authored Sep 28, 2024
2 parents 0ef1da9 + 7105385 commit 862044e
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 37 deletions.
Binary file added docs/assets/logEntityCount.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions docs/en_us.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,31 @@ binding.
`[<name>]` : fake player name

`[<state>]` : `true` or `false`

## Logger

### autosave

`/log autosave`

Simple logger that display when the server will autosave and how long ago the last autosave was.
This logger does not directly detect autosave, but rather a calculated value based on the time elapsed since the server started, which could be incorrect.
Ported from essential addons.

### entity_count

![logEntityCount](assets/logEntityCount.png)

`/log entity_count`

`/log entity_count [<entities>]`

Display counts of entities per dimension and the total number in the player list.

`[<entities>]` : entity id. you can input multiple values separated by commas.

※ if `:` is included, argument must be enclosed in double quotes.
```
/log entity_count player
/log entity_count "minecraft:player,minecraft:iron_golem"
```
102 changes: 65 additions & 37 deletions docs/ja_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,97 +4,97 @@

`/custom-load`コマンドの有効化。AMS の blockChunkLoader から発想を得ました。

- Type: `String`
- Default value: `ops`
- Allowed options: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- Categories: `SURVIVAL`, `COMMAND`, `VULPEUS`
- 型式: `String`
- 既定値: `ops`
- 使用可能な値: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- 分類: `SURVIVAL`, `COMMAND`, `VULPEUS`

### commandHat

`/hat`コマンドの有効化。essential addons からの移植。

- タイプ: `String`
- デフォルト: `ops`
- 利用可能な項目: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- カテゴリー: `SURVIVAL`, `COMMAND`, `VULPEUS`
- 型式: `String`
- 既定値: `ops`
- 使用可能な値: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- 分類: `SURVIVAL`, `COMMAND`, `VULPEUS`

### commandSit

`/sit`コマンドの有効化。PCA からの移植。

- タイプ: `String`
- デフォルト: `ops`
- 利用可能な項目: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- カテゴリー: `SURVIVAL`, `COMMAND`, `VULPEUS`
- 型式: `String`
- 既定値: `ops`
- 使用可能な値: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- 分類: `SURVIVAL`, `COMMAND`, `VULPEUS`

### commandView

`/view`コマンドの有効化。
carpet の viewDistance を変更することができる。

- タイプ: `String`
- デフォルト: `ops`
- 利用可能な項目: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- カテゴリー: `SURVIVAL`, `COMMAND`, `VULPEUS`
- 型式: `String`
- 既定値: `ops`
- 使用可能な値: `true`, `false`, `ops`, `0`, `1`, `2`, `3`, `4`
- 分類: `SURVIVAL`, `COMMAND`, `VULPEUS`

### defaultOpLevel

サーバーに参加したときにデフォルトでOPを付与する。
server.properties の`op-permission-level`を上書き可能。

- タイプ: `int`
- デフォルト: `0`
- カテゴリー: `CREATIVE`,`VULPEUS`
- 型式: `int`
- 既定値: `0`
- 分類: `CREATIVE`,`VULPEUS`

### disableCCECrash

ClassCastException によるサーバーのクラッシュの無効化。

- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `VULPEUS`

### disableSOECrash

StackOverflowError によるサーバーのクラッシュの無効化。

- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `VULPEUS`

### fixedBeeNotLeavingHive (<=1.21.1)

[MC-168329](https://bugs.mojang.com/browse/MC-168329) の修正。

- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `BUGFIX`, `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `BUGFIX`, `VULPEUS`

### fixedFallingBlockCantUseNetherPortal (<=1.20.6)

[MC-9644](https://bugs.mojang.com/browse/MC-9644) の修正。

- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `BUGFIX`, `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `BUGFIX`, `VULPEUS`

### fixedTickMemoriesEntityAI (<=1.20.1)

[MC-254100](https://bugs.mojang.com/browse/MC-254100) の修正

- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `BUGFIX`, `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `BUGFIX`, `VULPEUS`

### optmizedDragonRespawn

エンダードラゴンのリスポーン処理の最適化。carpet AMS addition からの移植。
> [!WARNING]
> このルールはバニラと同一の挙動を保証しません。
- タイプ: `boolean`
- デフォルト: `false`
- カテゴリー: `OPTIMIZATION`, `VULPEUS`
- 型式: `boolean`
- 既定値: `false`
- 分類: `OPTIMIZATION`, `VULPEUS`

## コマンド

Expand Down Expand Up @@ -144,3 +144,31 @@ StackOverflowError によるサーバーのクラッシュの無効化。
`[<name>]` : fake player の名前

`[<state>]` : `true``false`

## ロガー

### autosave

`/log autosave`

オートセーブされてからの時間と、次のオートセーブまでの時間をプレイヤーリストに表示。
このロガーはサーバー開始からのチックから算出されるため、正確ではない場合があることに留意してください。
essential addons からの移植。

### entity_count

![logEntityCount](assets/logEntityCount.png)

`/log entity_count`

`/log entity_count [<entities>]`

ディメンション毎と合計のエンティティの数をプレイヤーリストに表示。

`[<entities>]` : エンティティID。カンマ区切りで複数入力することも可能。`minecraft:`の接頭語は省略可。

`:`を含める場合は引数全体をダブルクォーテーションで囲う必要があります。
```
/log entity_count player
/log entity_count "minecraft:player,minecraft:iron_golem"
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.vulpeus.vulpeus_carpet.commands.hatCommand;
import com.vulpeus.vulpeus_carpet.commands.sitCommand;
import com.vulpeus.vulpeus_carpet.commands.viewCommand;
import com.vulpeus.vulpeus_carpet.loggers.VulpeusLoggerRegistry;
import com.vulpeus.vulpeus_carpet.utils.rule.commandCustomLoad.CustomLoadingChunks;
import com.vulpeus.vulpeus_carpet.utils.ScriptCollection;
import com.vulpeus.vulpeus_carpet.utils.rule.defaultOpLevel.PlayerUtil;
Expand Down Expand Up @@ -106,6 +107,11 @@ public void onServerClosed(MinecraftServer server) {
}
}

@Override
public void registerLoggers() {
VulpeusLoggerRegistry.registerLoggers();
}

@Override
public void registerCommands(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess commandRegistryAccess) {
customLoadCommand.register(dispatcher);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* This file is part of the VulpeusCarpet project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* VulpeusCarpet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VulpeusCarpet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with VulpeusCarpet. If not, see <https://www.gnu.org/licenses/>.
*/

package com.vulpeus.vulpeus_carpet.loggers;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;

public abstract class AbstractHUDLogger {
private final String NAME;

public AbstractHUDLogger(String name) {
this.NAME = name;
}

public String getName() {
return this.NAME;
}

public abstract Text[] onHudUpdate(String option, PlayerEntity playerEntity);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* This file is part of the VulpeusCarpet project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* VulpeusCarpet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VulpeusCarpet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with VulpeusCarpet. If not, see <https://www.gnu.org/licenses/>.
*/

package com.vulpeus.vulpeus_carpet.loggers;

import carpet.logging.HUDLogger;
import carpet.logging.LoggerRegistry;
import com.vulpeus.vulpeus_carpet.loggers.hud.autosave;
import com.vulpeus.vulpeus_carpet.loggers.hud.entity_count;
import java.lang.reflect.Field;

public class VulpeusLoggerRegistry {

public static boolean __autosave;
public static boolean __entity_count;

public static void registerLoggers(){
LoggerRegistry.registerLogger(autosave.NAME, standardHUDLogger(autosave.NAME, null, null));
LoggerRegistry.registerLogger(entity_count.NAME, standardHUDLogger(entity_count.NAME, null, null));
}

public static void updateHUD() {
doHudLogging(__autosave, autosave.getInstance());
doHudLogging(__entity_count, entity_count.getInstance());
}

public static HUDLogger standardHUDLogger(String logName, String def, String [] options) {
return new HUDLogger(getLoggerField(logName), logName, def, options, false);
}

public static Field getLoggerField(String logName) {
try {
return VulpeusLoggerRegistry.class.getField("__" + logName);
}
catch (NoSuchFieldException e) {
throw new RuntimeException();
}
}

private static void doHudLogging(boolean condition, AbstractHUDLogger logger) {
if (condition) {
LoggerRegistry.getLogger(logger.getName()).log(logger::onHudUpdate);
}
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/vulpeus/vulpeus_carpet/loggers/hud/autosave.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of the VulpeusCarpet project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* VulpeusCarpet is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VulpeusCarpet is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with VulpeusCarpet. If not, see <https://www.gnu.org/licenses/>.
*/

package com.vulpeus.vulpeus_carpet.loggers.hud;

import carpet.CarpetServer;
import carpet.utils.Messenger;
import com.vulpeus.vulpeus_carpet.loggers.AbstractHUDLogger;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.Text;

public class autosave extends AbstractHUDLogger {

public static final String NAME = "autosave";

private static final autosave INSTANCE = new autosave();

private autosave() {
super(NAME);
}

public static autosave getInstance() {
return INSTANCE;
}

@Override
public Text[] onHudUpdate(String option, PlayerEntity playerEntity) {

int gameTick = CarpetServer.minecraft_server.getTicks();
int previous = gameTick % 6000;

if (gameTick != 0 && previous == 0) {
previous = 6000;
}
int next = 6000 - previous;

String color = next <= 100 ? "§d" : next <= 500 ? "§c" : next <= 1000 ? "§e" : "§2";

return new Text[] {
Messenger.c(String.format("g Prev:%s %d §rNext:%s %d",color, previous, color, next))
};
}
}
Loading

0 comments on commit 862044e

Please sign in to comment.