Skip to content

Commit

Permalink
Updated to latest Slimefun version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Dec 1, 2020
1 parent 73c1d93 commit 2682411
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 60 deletions.
53 changes: 51 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>bstats-repo</id>
<url>https://repo.codemc.org/repository/maven-public</url>
</repository>
</repositories>

<build>
Expand All @@ -50,13 +54,51 @@
</includes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>

<configuration>

<!-- Shade dependencies into the output jar -->
<relocations>
<relocation>
<pattern>org.bstats.bukkit</pattern>
<shadedPattern>io.github.thebusybiscuit.slimefunluckyblocks.bstats</shadedPattern>
</relocation>
</relocations>

<!-- Exclude unneeded metadata files from shaded dependencies -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*</exclude>
</excludes>
</filter>
</filters>
</configuration>

<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -80,7 +122,7 @@
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-15</version>
<version>RC-17</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand All @@ -93,5 +135,12 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

public class LuckyBlock extends SlimefunItem {
private Collection<Surprise> surprises;
private Predicate<Surprise> predicate;

public LuckyBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
registerBlockHandler(getID(), (p, b, tool, reason) -> {
BlockStorage.clearBlockInfo(b);
b.setType(Material.AIR);
if (p != null) {
Random random = ThreadLocalRandom.current();
List<Surprise> luckySurprises = surprises.stream().filter(predicate).collect(Collectors.toList());
luckySurprises.get(random.nextInt(luckySurprises.size())).activate(random, p, b.getLocation());
}
return false;
});
}
public void register(SlimefunLuckyBlocks plugin, Collection<Surprise> surprises, Predicate<Surprise> predicate) {
this.surprises = surprises;
this.predicate = predicate;
super.register(plugin);
}

private Collection<Surprise> surprises;
private Predicate<Surprise> predicate;

public LuckyBlock(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);

registerBlockHandler(getId(), (p, b, tool, reason) -> {
BlockStorage.clearBlockInfo(b);
b.setType(Material.AIR);

if (p != null) {
Random random = ThreadLocalRandom.current();
List<Surprise> luckySurprises = surprises.stream().filter(predicate).collect(Collectors.toList());
luckySurprises.get(random.nextInt(luckySurprises.size())).activate(random, p, b.getLocation());
}
return false;
});
}

public void register(SlimefunLuckyBlocks plugin, Collection<Surprise> surprises, Predicate<Surprise> predicate) {
this.surprises = surprises;
this.predicate = predicate;
super.register(plugin);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Level;

import org.bstats.bukkit.Metrics;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
Expand Down Expand Up @@ -84,7 +85,6 @@
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.bstats.bukkit.Metrics;
import me.mrCookieSlime.Slimefun.cscorelib2.chat.ChatColors;
import me.mrCookieSlime.Slimefun.cscorelib2.config.Config;
import me.mrCookieSlime.Slimefun.cscorelib2.skull.SkullBlock;
Expand Down Expand Up @@ -122,13 +122,17 @@ public void onEnable() {
SlimefunItemStack veryUnluckyBlock = new SlimefunItemStack("LUCKY_BLOCK_UNLUCKY", TEXTURE, "&rVery unlucky Block", "&7Luck: &c-80");
SlimefunItemStack pandorasBox = new SlimefunItemStack("PANDORAS_BOX", "86c7dde512871bd607b77e6635ad39f44f2d5b4729e60273f1b14fba9a86a", "&5Pandora\"s Box", "&7Luck: &c&oERROR");

new LuckyBlock(category, luckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, new ItemStack(Material.DISPENSER), SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K }).register(this, surprises, s -> s.getLuckLevel() != LuckLevel.PANDORA);
new LuckyBlock(category, luckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] { SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, new ItemStack(Material.DISPENSER), SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K, SlimefunItems.GOLD_12K }).register(this, surprises, s -> s.getLuckLevel() != LuckLevel.PANDORA);

new LuckyBlock(category, veryLuckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { null, SlimefunItems.GOLD_12K, null, SlimefunItems.GOLD_12K, luckyBlock, SlimefunItems.GOLD_12K, null, SlimefunItems.GOLD_12K, null }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.LUCKY);
new LuckyBlock(category, veryLuckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] { null, SlimefunItems.GOLD_12K, null, SlimefunItems.GOLD_12K, luckyBlock, SlimefunItems.GOLD_12K, null, SlimefunItems.GOLD_12K, null }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.LUCKY);

new LuckyBlock(category, veryUnluckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { null, new ItemStack(Material.SPIDER_EYE), null, new ItemStack(Material.SPIDER_EYE), luckyBlock, new ItemStack(Material.SPIDER_EYE), null, new ItemStack(Material.SPIDER_EYE), null }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.UNLUCKY);
new LuckyBlock(category, veryUnluckyBlock, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] { null, new ItemStack(Material.SPIDER_EYE), null, new ItemStack(Material.SPIDER_EYE), luckyBlock, new ItemStack(Material.SPIDER_EYE), null, new ItemStack(Material.SPIDER_EYE), null }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.UNLUCKY);

new LuckyBlock(category, pandorasBox, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] { new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), luckyBlock, new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS) }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.PANDORA);
new LuckyBlock(category, pandorasBox, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] { new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), luckyBlock, new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS), new ItemStack(Material.LAPIS_BLOCK), new ItemStack(Material.OAK_PLANKS) }).register(this, surprises, s -> s.getLuckLevel() == LuckLevel.PANDORA);

new WorldGenerator(this);

Expand Down Expand Up @@ -210,8 +214,7 @@ private void registerCustomSurprises() {
if (cfg.getString("custom." + name + ".lucklevel") != null) {
try {
luckLevel = LuckLevel.valueOf(cfg.getString("custom." + name + ".lucklevel").toUpperCase());
}
catch (IllegalArgumentException ex) {
} catch (IllegalArgumentException ex) {
getLogger().log(Level.WARNING, "Couldn\"t load lucklevel of CustomItem Surprise \"{0}\", now using NEUTRAL (default)", name);
getLogger().log(Level.WARNING, "Valid lucklevel types: LUCKY, NEUTRAL, UNLUCKY, PANDORA");
}
Expand All @@ -236,12 +239,10 @@ private void registerCustomSurprises() {
if (cfg.getInt(itemPath + ".amount") > 1) {
item.setAmount(cfg.getInt(itemPath + ".amount"));
}
}
else {
} else {
getLogger().log(Level.WARNING, "Could not load SlimefunItem \"{0}\" to custom surprise \"{1}\"", new Object[] { id, name });
}
}
else if (cfg.getString(itemPath + ".type") != null && Material.getMaterial(cfg.getString(itemPath + ".type")) != null) {
} else if (cfg.getString(itemPath + ".type") != null && Material.getMaterial(cfg.getString(itemPath + ".type")) != null) {
item = new ItemStack(Material.getMaterial(cfg.getString(itemPath + ".type")));
ItemMeta itemMeta = item.getItemMeta();

Expand Down Expand Up @@ -279,8 +280,7 @@ else if (cfg.getString(itemPath + ".type") != null && Material.getMaterial(cfg.g
}

itemMeta.addEnchant(enchantment, level, true);
}
else {
} else {
getLogger().log(Level.WARNING, "Could not set \"{0}\" enchant for custom surprise \"{1}\"", new Object[] { enchName, name });
}
}
Expand Down Expand Up @@ -324,8 +324,7 @@ public void registerSurprise(Surprise surprise) {
if (cfg.getBoolean("events." + surprise.getName())) {
surprises.add(surprise);
}
}
else {
} else {
cfg.setValue("events." + surprise.getName(), true);
cfg.save();
surprises.add(surprise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
import me.mrCookieSlime.Slimefun.cscorelib2.materials.MaterialCollections;

public final class DiamondBlockPillarSurprise implements Surprise {

@Override
public String getName() {
return "Stained Clay Pillar with Diamond Block on top";
}

@Override
public void activate(Random random, Player p, Location l) {
for (int i = 0; i < 8; i++) {
l.getWorld().spawnFallingBlock(l.clone().add(0.5, (i + 1) * 4.0, 0.5), MaterialCollections.getAllTerracottaColors().get(i).createBlockData());
}
l.getWorld().spawnFallingBlock(l.clone().add(0.5, 9 * 4.0, 0.5), Material.DIAMOND_BLOCK.createBlockData());
}

@Override
public LuckLevel getLuckLevel() {
return LuckLevel.LUCKY;
}

@Override
public String getName() {
return "Stained Clay Pillar with Diamond Block on top";
}

@Override
public void activate(Random random, Player p, Location l) {
for (int i = 0; i < 8; i++) {
l.getWorld().spawnFallingBlock(l.clone().add(0.5, (i + 1) * 4.0, 0.5), MaterialCollections.getAllTerracottaColors().get(i).createBlockData());
}

l.getWorld().spawnFallingBlock(l.clone().add(0.5, 9 * 4.0, 0.5), Material.DIAMOND_BLOCK.createBlockData());
}

@Override
public LuckLevel getLuckLevel() {
return LuckLevel.LUCKY;
}

}

0 comments on commit 2682411

Please sign in to comment.