-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a19c708
commit 55e9c02
Showing
9 changed files
with
222 additions
and
8 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
src/main/java/de/florianmichael/viafabricplus/injection/access/IBlobCache.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,28 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus | ||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.florianmichael.viafabricplus.injection.access; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public interface IBlobCache { | ||
|
||
Map<Long, CompletableFuture<byte[]>> viaFabricPlus$getPending(); | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/de/florianmichael/viafabricplus/injection/mixin/viabedrock/MixinBlobCache.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,42 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus | ||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.florianmichael.viafabricplus.injection.mixin.viabedrock; | ||
|
||
import de.florianmichael.viafabricplus.injection.access.IBlobCache; | ||
import net.raphimc.viabedrock.protocol.storage.BlobCache; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@Mixin(value = BlobCache.class, remap = false) | ||
public class MixinBlobCache implements IBlobCache { | ||
|
||
@Shadow | ||
@Final | ||
private Map<Long, CompletableFuture<byte[]>> pending; | ||
|
||
@Override | ||
public Map<Long, CompletableFuture<byte[]>> viaFabricPlus$getPending() { | ||
return pending; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/java/de/florianmichael/viafabricplus/util/StringUtil.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,48 @@ | ||
/* | ||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus | ||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD | ||
* Copyright (C) 2023 RK_01/RaphiMC and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.florianmichael.viafabricplus.util; | ||
|
||
import java.text.DecimalFormat; | ||
|
||
// Stolen from https://github.com/FlorianMichael/RClasses/blob/main/common/src/main/java/de/florianmichael/rclasses/common/StringUtils.java | ||
public class StringUtil { | ||
|
||
/** | ||
* Convention: IEC 60027-2 | ||
*/ | ||
private final static String[] BYTES_UNIT = {"B", "KiB", "MiB", "GiB", "TiB"}; | ||
private final static DecimalFormat OPTIONAL_FORMAT = new DecimalFormat("#.##"); | ||
|
||
/** | ||
* Formats a value in bytes to a human-readable format | ||
* | ||
* @param value The raw value in bytes | ||
* @return The formatted value in bytes | ||
*/ | ||
public static String formatBytes(final long value) { | ||
int index = (int) (Math.log(value) / Math.log(1024.0)); | ||
double data = value / Math.pow(1024.0, index); | ||
if (index < 0) index = 0; | ||
if (Double.isNaN(data)) data = 0; | ||
|
||
return OPTIONAL_FORMAT.format(data) + " " + BYTES_UNIT[index]; | ||
} | ||
|
||
} |
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