Skip to content

Commit

Permalink
gcp dot api. fune
Browse files Browse the repository at this point in the history
  • Loading branch information
Soumeh committed Dec 9, 2024
1 parent 297bfb3 commit e5c00c8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/nuclearcrackhead/serverboss/SVBCR.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.nuclearcrackhead.serverboss;

import com.nuclearcrackhead.serverboss.registry.*;
import com.nuclearcrackhead.serverboss.registry.ModBlocks;
import com.nuclearcrackhead.serverboss.registry.ModFluids;
import com.nuclearcrackhead.serverboss.registry.ModItems;
import com.nuclearcrackhead.serverboss.registry.ModDamageTypes;
import net.fabricmc.api.ModInitializer;

import net.minecraft.util.Identifier;
Expand All @@ -22,6 +25,5 @@ public void onInitialize() {
ModFluids.init();
ModBlocks.init();
ModDamageTypes.init();
ModSounds.init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.nuclearcrackhead.serverboss.api.gcp.dot;

import com.google.common.util.concurrent.AtomicDouble;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class GcpDotAPI {

protected static final AtomicDouble INDEX = new AtomicDouble(0);

protected static final URI GCP_DOT_INDEX_URL = URI.create("https://gcpdot.com/gcpindex.php");
protected static final Pattern INDEX_PATTERN = Pattern.compile("'>(.*?)<");

protected static boolean STARTED = false;

public static void start() {
if (STARTED) return;

GcpDotFetcher fetcher = new GcpDotFetcher();
Thread thread = new Thread(fetcher);
thread.setName("gcp_dot_fetcher_service");
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
STARTED = true;
}

public static Double getIndex() {
return INDEX.get();
}

public static class GcpDotFetcher implements Runnable {

@Override
public void run() {
try {
while (true) {
URL oracle = GCP_DOT_INDEX_URL.toURL();
BufferedReader reader = new BufferedReader(new InputStreamReader(oracle.openStream()));
String text = reader.lines().collect(Collectors.joining());
Matcher matcher = INDEX_PATTERN.matcher(text);
while (matcher.find()) {
String rawIndex = matcher.group().split("'>")[1].split("<")[0];
double index = Double.parseDouble(rawIndex);
INDEX.set(index);
TimeUnit.SECONDS.sleep(1);
}
}
} catch (InterruptedException | IOException ignored) {}
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.nuclearcrackhead.serverboss.content.item;

import com.nuclearcrackhead.serverboss.api.gcp.dot.GcpDotAPI;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

public class GcpDotTestingItem extends Item {

public GcpDotTestingItem(Settings settings) {
super(settings);
}

@Override
public ActionResult use(World world, PlayerEntity user, Hand hand) {
if (world.isClient) return ActionResult.SUCCESS;
user.sendMessage(
Text.of(GcpDotAPI.getIndex().toString()),
false
);
return ActionResult.SUCCESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.nuclearcrackhead.serverboss.SVBCR;
import com.nuclearcrackhead.serverboss.content.item.ExampleItem;
import com.nuclearcrackhead.serverboss.content.item.GcpDotTestingItem;
import net.minecraft.fluid.Fluid;
import net.minecraft.item.BucketItem;
import net.minecraft.item.Item;
Expand All @@ -25,6 +26,9 @@ public static void init() {}
public static final Item EXAMPLE_ITEM = register("example_item", ExampleItem::new,
new Item.Settings()
);
public static final Item GCP_DOT_TESTING_ITEM = register("gcp_dot_testing_item", GcpDotTestingItem::new,
new Item.Settings()
);
public static Item RADIOACTIVE_BUCKET = register("radioactive_bucket",
settings -> new BucketItem(RADIOACTIVE_STILL, settings),
new Item.Settings().recipeRemainder(Items.BUCKET).maxCount(1)
Expand Down

0 comments on commit e5c00c8

Please sign in to comment.