generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Vulpeus-Server/feature/loggers
- Loading branch information
Showing
11 changed files
with
435 additions
and
37 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/vulpeus/vulpeus_carpet/loggers/AbstractHUDLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/com/vulpeus/vulpeus_carpet/loggers/VulpeusLoggerRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
60
src/main/java/com/vulpeus/vulpeus_carpet/loggers/hud/autosave.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}; | ||
} | ||
} |
Oops, something went wrong.