Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Feb 8, 2020
1 parent ff1deb9 commit a3bcbae
Show file tree
Hide file tree
Showing 102 changed files with 3,868 additions and 3,110 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ This is solely for statistical purposes, as we are interested in how Servers/Pla
All available data is anonymous and aggregated, at no point can we see individual server or player information.<br>
All of the collected data is publicly accessible: https://bstats.org/plugin/bukkit/Slimefun/4574

You can also disable this behaviour under `/plugins/bStats/config.yml`.<br>
For more info see [bStats' Privacy Policy](https://bstats.org/privacy-policy)
你可以在 `/plugins/bStats/config.yml` 下关闭.<br>
详情请查看 [bStats 隐私政策](https://bstats.org/privacy-policy)

### GitHub Integration
Lastly, Slimefun4 connects to https://api.github.com/ to gather information about this open-source project.<br>
No information about your Minecraft Server is sent to GitHub.
最近, Slimefun4 连接到了 https://api.github.com/ 以收集关于这个开源项目的信息.<br>
请放心, 你的 Minecraft 服务器信息不会被发送到 Github.

This information includes (but is not limited to)
这些信息包括 (但不限于)
* list of contributors, their username and profile link (from the repositories `TheBusyBiscuit/Slimefun4`, `TheBusyBiscuit/Slimefun4-Wiki` and `TheBusyBiscuit/Slimefun4-Resourcepack`)
* amount of open issues in this repository
* amount of pending pull requests in this repository
Expand All @@ -77,4 +77,4 @@ This information includes (but is not limited to)
* amount of code-bytes in this repository
* date of the last commit to this repository

Additionally the plugin connects to https://mojang.com/ to retrieve the Minecraft skins of our contributors (if possible).
另外, 插件还连接到了 https://mojang.com/ 以获取贡献者的 Minecraft 皮肤 (如果有的话).
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.mrCookieSlime</groupId>
<artifactId>Slimefun</artifactId>
<version>4.2-UNOFFCIAL-20200206</version>
<version>4.2-UNOFFCIAL-20200208</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -47,6 +47,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
107 changes: 0 additions & 107 deletions src/main/java/io/github/thebusybiscuit/slimefun4/api/SlimefunAPI.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,47 +1,66 @@
package io.github.thebusybiscuit.slimefun4.api.geo;

import org.bukkit.Chunk;
import org.bukkit.Keyed;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public interface GEOResource {

/**
* Returns the default supply of this resource in that biome
*
* @return The default supply found in a {@link Chunk} with the given {@link Biome}
*/
int getDefaultSupply(Biome biome);

/**
* Name/ID e.g. "Oil"
*
* @return The name of this Resource
*/
String getName();

/**
* This {@link ItemStack} is used for display-purposes in the GEO Scanner.
* But will also determine the Output of the GEO Miner, if it is applicable for that.
*
* @return The {@link ItemStack} version of this Resource.
*/
ItemStack getItem();

/**
* Measurement Unit e.g. "Bucket" / "Buckets".
* Use the amount parameter to determine whether to use singular or plural.
*
* @return The Measurement Unit for this resource, will be treated like a suffix.
*/
String getMeasurementUnit(int amount);

/**
* Returns whether this Resource can be obtained using a GEO Miner.
* This will automatically add it to the GEO - Miner.
*
* @return Whether you can get obtain this resource using a GEO Miner.
*/
boolean isObtainableFromGEOMiner();

}
import me.mrCookieSlime.Slimefun.SlimefunPlugin;

public interface GEOResource extends Keyed {

/**
* Returns the default supply of this resource in that biome
*
* @param environment The {@link Environment} this area is currently in (NORMAL / NETHER / THE_END)
* @param biome The {@link Biome} this area is currently in.
*
* @return The default supply found in a {@link Chunk} with the given {@link Biome}
*/
int getDefaultSupply(Environment environment, Biome biome);

/**
* Returns how much the value may deviate from the default supply (positive only).
*
* @return The deviation or spread of the supply
*/
int getMaxDeviation();

/**
* Returns the name of this resource (e.g. "Oil")
*
* @return The name of this Resource
*/
String getName();

/**
* This {@link ItemStack} is used for display-purposes in the GEO Scanner.
* But will also determine the Output of the GEO Miner, if it is applicable for that.
*
* @return The {@link ItemStack} version of this Resource.
*/
ItemStack getItem();

/**
* Returns whether this Resource can be obtained using a GEO Miner.
* This will automatically add it to the GEO - Miner.
*
* @return Whether you can get obtain this resource using a GEO Miner.
*/
boolean isObtainableFromGEOMiner();

/**
* Registers this GEO Resource
*/
default void register() {
SlimefunPlugin.getGPSNetwork().getResourceManager().register(this);
}

default String getName(Player p) {
String name = SlimefunPlugin.getLocal().getResourceString(p, "resources." + getKey().getNamespace() + "." + getKey().getKey());
return name == null ? getName(): name;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package io.github.thebusybiscuit.slimefun4.api.geo;

import java.util.OptionalInt;
import java.util.concurrent.ThreadLocalRandom;

import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.skull.SkullItem;
import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.BlockStorage;

public class ResourceManager {

private final int[] backgroundSlots = {0, 1, 2, 3, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53};
private final ItemStack chunkTexture = SkullItem.fromBase64("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODQ0OWI5MzE4ZTMzMTU4ZTY0YTQ2YWIwZGUxMjFjM2Q0MDAwMGUzMzMyYzE1NzQ5MzJiM2M4NDlkOGZhMGRjMiJ9fX0=");
private final Config config = new Config("plugins/Slimefun/resources.yml");

public void register(GEOResource resource) {
boolean enabled = config.getOrSetDefault(resource.getKey().toString().replace(':', '.') + ".enabled", true);

if (enabled) {
SlimefunPlugin.getRegistry().getGEOResources().add(resource);
}

config.save();
}

public OptionalInt getSupplies(GEOResource resource, World world, int x, int z) {
String key = resource.getKey().toString().replace(':', '-');

String value = BlockStorage.getChunkInfo(world, x, z, key);

if (value != null) {
return OptionalInt.of(Integer.parseInt(value));
}
else {
return OptionalInt.empty();
}
}

public void setSupplies(GEOResource resource, World world, int x, int z, int value) {
String key = resource.getKey().toString().replace(':', '-');
BlockStorage.setChunkInfo(world, x, z, key, String.valueOf(value));
}

private int generate(GEOResource resource, World world, int x, int z) {
Block block = world.getBlockAt(x << 4, 72, z << 4);
int value = resource.getDefaultSupply(world.getEnvironment(), block.getBiome());

if (value > 0) {
value += ThreadLocalRandom.current().nextInt(resource.getMaxDeviation());
}

setSupplies(resource, world, x, z, value);
return value;
}

public void scan(Player p, Block block) {
if (SlimefunPlugin.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) {
SlimefunPlugin.getLocal().sendMessages(p, "gps.insufficient-complexity", true, msg -> msg.replace("%complexity%", "600"));
return;
}

int x = block.getX() >> 4;
int z = block.getZ() >> 4;

ChestMenu menu = new ChestMenu("&4" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.results"));

for (int slot : backgroundSlots) {
menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler());
}

menu.addItem(4, new CustomItem(chunkTexture,
"&e" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.chunk"),
"",
"&8\u21E8 &7" + SlimefunPlugin.getLocal().getResourceString(p, "tooltips.world") + ": " + block.getWorld().getName(),
"&8\u21E8 &7X: " + x + " Z: " + z
), ChestMenuUtils.getEmptyClickHandler());

int index = 10;

for (GEOResource resource : SlimefunPlugin.getRegistry().getGEOResources().values()) {
OptionalInt optional = getSupplies(resource, block.getWorld(), x, z);
int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, z);
String suffix = SlimefunPlugin.getLocal().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units");

ItemStack item = new CustomItem(resource.getItem(), "&r" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix);

if (supplies > 1) {
item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize(): supplies);
}

menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler());
index++;

if (index % 9 == 8) {
index += 2;
}
}

menu.open(p);
}

}
Loading

0 comments on commit a3bcbae

Please sign in to comment.