Skip to content

Commit

Permalink
Update to 1.18.2
Browse files Browse the repository at this point in the history
  • Loading branch information
CECoffee committed Jul 17, 2022
1 parent d3784f9 commit 6b03251
Show file tree
Hide file tree
Showing 24 changed files with 120 additions and 113 deletions.
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
`java-library`
id ("com.github.johnrengelman.shadow") version "7.1.1"
id("io.papermc.paperweight.userdev") version "1.3.3"
id ("com.github.johnrengelman.shadow") version "7.1.2"
id("io.papermc.paperweight.userdev") version "1.3.6"
id("xyz.jpenilla.run-paper") version "1.0.6" // Adds runServer and runMojangMappedServer tasks for testing
id("net.minecrell.plugin-yml.bukkit") version "0.5.1"
id("net.minecrell.plugin-yml.bukkit") version "0.5.2"
}

group = "me.chickenstyle.luckyblocks"
version = "1.0.7"
version = "1.0.8"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
Expand All @@ -26,10 +26,10 @@ repositories {
}
}
dependencies {
paperDevBundle("1.18.1-R0.1-SNAPSHOT")
paperDevBundle("1.18.2-R0.1-SNAPSHOT")

//Shaded
implementation("net.kyori:adventure-text-minimessage:4.10.0-SNAPSHOT") {
implementation("net.kyori:adventure-text-minimessage:4.11.0-SNAPSHOT") {
exclude(group = "net.kyori", module = "adventure-api")
exclude(group = "net.kyori", module = "adventure-bom")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public enum AnimationType {
GUI,
NONE,
SPINNING;
SPINNING
}
23 changes: 12 additions & 11 deletions src/main/java/me/chickenstyle/luckyblocks/LuckyCubesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
import org.bukkit.conversations.ConversationFactory;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

public class LuckyCubesCommand implements CommandExecutor {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
if (args.length >= 1) {
switch (args[0].toLowerCase()) {
case "addluckycube":
if (sender instanceof Player) {
Player player = (Player) sender;
if (player.hasPermission("LuckyCubes.Admin") || player.hasPermission("LuckyCubes." + args[0].toString().toLowerCase())) {
Main.creatingLuckyCube.put(player.getUniqueId(), new LuckyCube(0, "", null, "", new ArrayList<String>(), null, null));
if (sender instanceof Player player) {
if (player.hasPermission("LuckyCubes.Admin") || player.hasPermission("LuckyCubes." + args[0].toLowerCase())) {
Main.creatingLuckyCube.put(player.getUniqueId(), new LuckyCube(0, "", null, "", new ArrayList<>(), null, null));
ConversationFactory factory = new ConversationFactory(Main.getInstance());
Conversation conversation = factory.withFirstPrompt(new IdPrompt()).withLocalEcho(true).buildConversation(player);
conversation.begin();
Expand All @@ -36,7 +36,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
break;

case "reload":
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toString().toLowerCase())) {
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toLowerCase())) {
CustomLuckyBlocks.reloadConfig();
Main.getInstance().saveConfig();
Main.getInstance().reloadConfig();
Expand All @@ -49,16 +49,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
break;

case "give":
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toString().toLowerCase())) {
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toLowerCase())) {
if (args.length == 4) {
if (Bukkit.getServer().getOnlinePlayers().contains(Bukkit.getPlayer(args[1]))) {
if (isInt(args[2])) {
if (CustomLuckyBlocks.hasLuckyCube(Integer.valueOf(args[2]))) {
if (CustomLuckyBlocks.hasLuckyCube(Integer.parseInt(args[2]))) {
if (isInt(args[3])) {
Player target = Bukkit.getPlayer(args[1]);
LuckyCube cube = CustomLuckyBlocks.getLuckyCubeByID(Integer.valueOf(args[2]));
LuckyCube cube = CustomLuckyBlocks.getLuckyCubeByID(Integer.parseInt(args[2]));
ItemStack cubes = Utils.createLuckyCube(cube);
cubes.setAmount(Integer.valueOf(args[3]));
cubes.setAmount(Integer.parseInt(args[3]));
assert target != null;
if (target.getInventory().firstEmpty() != -1) {
target.getInventory().addItem(cubes);
} else {
Expand Down Expand Up @@ -92,7 +93,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
break;

case "help":
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toString().toLowerCase())) {
if (sender.hasPermission("LuckyCubes.Admin") || sender.hasPermission("LuckyCubes." + args[0].toLowerCase())) {
sender.sendMessage(Utils.color("&f----------[LuckyCubes]----------"));
sender.sendMessage(ChatColor.WHITE + "/lc give {player} {luckycube_id}");
sender.sendMessage(ChatColor.WHITE + "");
Expand Down
41 changes: 19 additions & 22 deletions src/main/java/me/chickenstyle/luckyblocks/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.chickenstyle.luckyblocks.events.CloseInventory;
import me.chickenstyle.luckyblocks.events.PlaceBlockEvent;
import me.chickenstyle.luckyblocks.events.PlayerStandManipulateEvent;
import me.chickenstyle.luckyblocks.versions.Handler_1_18_R1;
import me.chickenstyle.luckyblocks.versions.Handler_1_18_R2;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
Expand All @@ -26,7 +26,7 @@ public class Main extends JavaPlugin{
public static Set<UUID> opening;
public static HashMap<UUID,LuckyCube> creatingLuckyCube;
private static NMSHandler versionHandler;
private static Main instance;;
private static Main instance;
private MiniMessage miniMessage;


Expand All @@ -41,9 +41,9 @@ public void onEnable() {
getServerVersion();

instance = this;
opening = new HashSet<UUID>();
creatingLuckyCube = new HashMap<UUID,LuckyCube>();
stands = new HashSet<ArmorStand>();
opening = new HashSet<>();
creatingLuckyCube = new HashMap<>();
stands = new HashSet<>();

File config = new File(getDataFolder(),"config.yml");

Expand All @@ -54,7 +54,7 @@ public void onEnable() {
new CustomLuckyBlocks(this);

//Loads proper data :)
recipes = new ArrayList<NamespacedKey>();
recipes = new ArrayList<>();


//Getting data
Expand All @@ -66,8 +66,8 @@ public void onEnable() {
loadListeners();
loadRecipes();

getCommand("luckycubes").setExecutor(new LuckyCubesCommand());
getCommand("luckycubes").setTabCompleter(new LuckyTab());
Objects.requireNonNull(getCommand("luckycubes")).setExecutor(new LuckyCubesCommand());
Objects.requireNonNull(getCommand("luckycubes")).setTabCompleter(new LuckyTab());

getServer().getConsoleSender().sendMessage(Utils.color("&aLuckyCubes plugin has been enabled!"));

Expand All @@ -85,9 +85,9 @@ public void onDisable() {


ArrayList<LuckyCube> luckyBlocks = CustomLuckyBlocks.getLuckyCubes();
if (!luckyBlocks.isEmpty() && luckyBlocks != null) {
for (LuckyCube pack:luckyBlocks) {
removeRecipe(pack.getRecipe());
if (!luckyBlocks.isEmpty()) {
for (LuckyCube ignored :luckyBlocks) {
removeRecipe();
}
}
}
Expand All @@ -97,14 +97,12 @@ public void getServerVersion() {
String version = Bukkit.getServer().getClass().getPackage().getName();
version = version.substring(version.lastIndexOf(".") + 1);
boolean isValid = true;
if ("v1_18_R1".equals(version)) {
versionHandler = new Handler_1_18_R1();
} else {
if (!"v1_18_R2".equals(version)) {
isValid = false;
getServer().getConsoleSender().sendMessage(parse("<RED>LuckyCubes >>> This version isn't supported!"));
getServer().getConsoleSender().sendMessage(parse("<YELLOW>LuckyCubes >>> LuckyCubes will run anyways. However, I cannot guarantee that it will work."));
versionHandler = new Handler_1_18_R1();
}
versionHandler = new Handler_1_18_R2();
if (isValid) {
getServer().getConsoleSender().sendMessage(parse("<GREEN>LuckyCubes >>> NMS Version Detected: " + version));
}
Expand All @@ -122,16 +120,16 @@ public void loadListeners() {
public void loadRecipes() {
ArrayList<LuckyCube> luckyBlocks = CustomLuckyBlocks.getLuckyCubes();

if (!luckyBlocks.isEmpty() && luckyBlocks != null) {
if (!luckyBlocks.isEmpty()) {
for (LuckyCube lucky: luckyBlocks) {
if (lucky.getRecipe() != null) removeRecipe(lucky.getRecipe());
if (lucky.getRecipe() != null) removeRecipe();
}

}



if (!luckyBlocks.isEmpty() && luckyBlocks != null) {
if (!luckyBlocks.isEmpty()) {
int recipesAmount = 0;
for (LuckyCube lucky:luckyBlocks) {

Expand All @@ -154,14 +152,13 @@ public void loadRecipes() {
}
}

public void removeRecipe(ShapedRecipe inputRecipe){
public void removeRecipe(){
Iterator<Recipe> it = getServer().recipeIterator();

while(it.hasNext()){
Recipe itRecipe = it.next();
if(itRecipe instanceof ShapedRecipe){
ShapedRecipe itShaped = (ShapedRecipe) itRecipe;
if (recipes.contains(itShaped.getKey())) {
if(itRecipe instanceof ShapedRecipe itShaped){
if (recipes.contains(itShaped.getKey())) {
it.remove();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/chickenstyle/luckyblocks/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum Message {
COOLDOWN(color(getString("messages.cooldown"))),
PLACE_ON_GROUND(color(getString("messages.placeOnGround"))),
DISABLE_COMMAND(color(getString("messages.disableCommandUse")));
private String error;
private final String error;

Message(String error) {
this.error = error;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/chickenstyle/luckyblocks/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class Metrics {
private static final String URL = "https://bStats.org/submitData/bukkit";

// Is bStats enabled on this server?
private boolean enabled;
private final boolean enabled;

// Should failed requests be logged?
private static boolean logFailedRequests;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/me/chickenstyle/luckyblocks/NMSHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.bukkit.inventory.ItemStack;

public interface NMSHandler {
public ItemStack addLuckyBlockID(ItemStack item,int id);
public boolean isLuckyBlock(ItemStack item);
public int getLuckyBlockID(ItemStack item);
public void playParticles(World world,Location loc,String particle,int amount);
ItemStack addLuckyBlockID(ItemStack item,int id);
boolean isLuckyBlock(ItemStack item);
int getLuckyBlockID(ItemStack item);
void playParticles(World world,Location loc,String particle,int amount);
}
9 changes: 5 additions & 4 deletions src/main/java/me/chickenstyle/luckyblocks/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public static ItemStack createCustomSkull(String displayName, String texture) {
public static ItemStack createCustomSkull(String displayName, String texture,ArrayList<String> lore) {
ArrayList<String> coloredLore = new ArrayList<>();
ItemStack skull = createCustomSkull(displayName, texture);
ItemMeta meta = skull.getItemMeta();
assert skull != null;
ItemMeta meta = skull.getItemMeta();
for (String str:lore) {
coloredLore.add(color(str));
}
Expand Down Expand Up @@ -165,10 +166,10 @@ public static void givePrize(Player player,ItemStack prize) {
}

public static String arrayToString(String[] arr) {
String str = "";
StringBuilder str = new StringBuilder();
for (String chr:arr) {
str = str + chr;
str.append(chr);
}
return str;
return str.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void run() {

ticks = ticks + 2;
} else {
if (runOnce == false) {
if (!runOnce) {
stand.setHelmet(new ItemStack(Material.AIR));
loc = stand.getLocation().clone().subtract(0,0.6,0);
stand.setRightArmPose(new EulerAngle(-(Math.PI / 2), -0.69, 0));
Expand All @@ -78,6 +78,7 @@ public void run() {
Main.stands.add(text);

String title = Main.getInstance().getConfig().getString("spinningAnimation.armortandTitle");
assert title != null;
title = title.replace("{player}", player.getName());
title = title.replace("{amount}", prize.getAmount() + "");
if (prize.getItemMeta().hasDisplayName()) {
Expand Down Expand Up @@ -109,7 +110,6 @@ public void run() {
player.playSound(player.getLocation(), Utils.getChestCloseSound(), 1f, 1f);
cancel();
Main.opening.remove(player.getUniqueId());
return;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

public class CustomLuckyBlocks {

Expand Down Expand Up @@ -63,19 +64,18 @@ public CustomLuckyBlocks(Main main) {
*
*/
static public ArrayList<LuckyCube> getLuckyCubes(){
ArrayList<LuckyCube> list = new ArrayList<LuckyCube>();
if (config.getConfigurationSection("LuckyCubes") == null) return new ArrayList<LuckyCube>();
for (String path:config.getConfigurationSection("LuckyCubes").getKeys(false)) {
int id = Integer.valueOf(path);
ArrayList<LuckyCube> list = new ArrayList<>();
if (config.getConfigurationSection("LuckyCubes") == null) return new ArrayList<>();
for (String path: Objects.requireNonNull(config.getConfigurationSection("LuckyCubes")).getKeys(false)) {
int id = Integer.parseInt(path);
list.add(getLuckyCubeByID(id));
}
return list;


}

@SuppressWarnings("deprecation")
static public void addLuckyCube(LuckyCube lucky,HashMap<Character,ItemStack> map) {
static public void addLuckyCube(LuckyCube lucky,HashMap<Character,ItemStack> map) {
config = YamlConfiguration.loadConfiguration(file);
String path = "LuckyCubes." + lucky.getId();

Expand All @@ -89,7 +89,7 @@ static public void addLuckyCube(LuckyCube lucky,HashMap<Character,ItemStack> map
try {
config.set(path + ".craftRecipe", lucky.getRecipe().getShape());

ArrayList<String> ingredients = new ArrayList<String>();
ArrayList<String> ingredients = new ArrayList<>();

for (char symbol:map.keySet()) {
if (map.get(symbol) != null && map.get(symbol).getType() != Material.AIR) {
Expand All @@ -111,12 +111,12 @@ static public void addLuckyCube(LuckyCube lucky,HashMap<Character,ItemStack> map
}
}

@SuppressWarnings({ "deprecation", "unchecked" })
@SuppressWarnings({"unchecked" })
static public LuckyCube getLuckyCubeByID(int id) {
String path = "LuckyCubes." + id;

String title = config.getString(path + ".title");
AnimationType type = AnimationType.valueOf(config.getString(path + ".animationType").toUpperCase());
AnimationType type = AnimationType.valueOf(Objects.requireNonNull(config.getString(path + ".animationType")).toUpperCase());
String texture = config.getString(path + ".texture");
ArrayList<String> lore = (ArrayList<String>) config.get(path + ".lore");
ArrayList<ItemStack> items = (ArrayList<ItemStack>) config.get(path + ".items");
Expand All @@ -126,13 +126,14 @@ static public LuckyCube getLuckyCubeByID(int id) {
ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(Main.getInstance(),path),item);


if (!config.get(path + ".craftRecipe").equals("none")) {
if (!Objects.equals(config.get(path + ".craftRecipe"), "none")) {
ArrayList<String> str = (ArrayList<String>) config.get(path + ".craftRecipe");
String[] someList = {};
assert str != null;
recipe.shape(str.toArray(someList));


for (String data: (ArrayList<String>)config.getList(path + ".ingredients")) {
for (String data: (ArrayList<String>) Objects.requireNonNull(config.getList(path + ".ingredients"))) {
char symbol = data.split(":")[0].charAt(0);
ItemStack mat = new ItemStack(Material.valueOf(data.split(":")[1].split(",")[0]));
recipe.setIngredient(symbol, mat.getType());
Expand All @@ -146,11 +147,8 @@ static public LuckyCube getLuckyCubeByID(int id) {
}

static public boolean hasLuckyCube(int id) {
if (config.get("LuckyCubes." + id) != null) {
return true;
}
return false;
}
return config.get("LuckyCubes." + id) != null;
}

static public void reloadConfig() {
config = YamlConfiguration.loadConfiguration(file);
Expand Down
Loading

0 comments on commit 6b03251

Please sign in to comment.