Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrisen authored Mar 18, 2024
1 parent 764d703 commit 5548cad
Show file tree
Hide file tree
Showing 7 changed files with 300 additions and 99 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>cloud.thehsi</groupId>
<artifactId>SharedEnderPearls</artifactId>
<version>1.2</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>SharedEnderPearls</name>
Expand Down
116 changes: 45 additions & 71 deletions src/main/java/cloud/thehsi/sharedenderpearls/Commands/Sep.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,115 +10,89 @@
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;

public class Sep implements CommandExecutor, TabCompleter {
Plugin plugin;
Main main;
List<String> options;

public Sep(Plugin plugin, Main main) {
this.plugin = plugin;
this.main = main;
options = new ArrayList<>(main.settings.keySet());
}

@SuppressWarnings("NullableProblems")
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
List<String> args = new ArrayList<>();
List<String> options = new ArrayList<>();
options.add("enabled");
options.add("canStealPearls");
options.add("disablePostTeleportFallDamage");
switch (strings.length) {
case 1:
args.addAll(options);
break;
case 2:
case 1 -> {
if (main.settings.get("enabled")) {
args.add("*");
args.addAll(options);
}else {
args.add("enabled");
}
}
case 2 -> {
if (options.contains(strings[0])) {
args.add("true");
args.add("false");
}
break;
default:
args.add("");
break;
}
default -> args.add("");
}
return args;
}

@SuppressWarnings("NullableProblems")
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (strings.length == 2) {
ToolBelt tb = new ToolBelt(plugin);
TextComponent msg;
switch (strings[0]) {
case "canStealPearls":
if (Objects.equals(strings[1], "true")) {
main.settings.replace("canStealPearls", true);
} else if (Objects.equals(strings[1], "false")) {
main.settings.replace("canStealPearls", false);
} else {
msg = tb.sendAsPlugin(ChatColor.RED + "Cannot set 'canStealPearls' to " + strings[1]);
commandSender.spigot().sendMessage(msg);
break;
}
msg = tb.sendAsPlugin("Rule 'enabled' is now " + main.settings.get("canStealPearls"));
commandSender.spigot().sendMessage(msg);
break;
case "enabled":
if (Objects.equals(strings[1], "true")) {
main.settings.replace("enabled", true);
} else if (Objects.equals(strings[1], "false")) {
main.settings.replace("enabled", false);
} else {
msg = tb.sendAsPlugin(ChatColor.RED + "Cannot set 'enabled' to " + strings[1]);
commandSender.spigot().sendMessage(msg);
break;
}
msg = tb.sendAsPlugin("Rule 'enabled' is now " + main.settings.get("enabled"));
commandSender.spigot().sendMessage(msg);
break;
case "disablePostTeleportFallDamage":
ToolBelt tb = new ToolBelt(plugin);
TextComponent msg;
switch (strings.length) {
case 2 -> {
if (options.contains(strings[0])) {
if (Objects.equals(strings[1], "true")) {
main.settings.replace("disablePostTeleportFallDamage", true);
main.settings.replace(strings[0], true);
} else if (Objects.equals(strings[1], "false")) {
main.settings.replace("disablePostTeleportFallDamage", false);
main.settings.replace(strings[0], false);
} else {
msg = tb.sendAsPlugin(ChatColor.RED + "Cannot set 'disablePostTeleportFallDamage' to " + strings[1]);
msg = tb.sendAsPlugin(ChatColor.RED + "Cannot set '" + strings[0] + "' to " + strings[1]);
commandSender.spigot().sendMessage(msg);
break;
return false;
}
msg = tb.sendAsPlugin("Rule 'disablePostTeleportFallDamage' is now " + main.settings.get("disablePostTeleportFallDamage"));
msg = tb.sendAsPlugin("Rule '" + strings[0] + "' is now " + main.settings.get(strings[0]));
commandSender.spigot().sendMessage(msg);
break;
default:
return true;
} else {
msg = tb.sendAsPlugin(ChatColor.RED + "Rule '" + strings[0] + "' not found");
commandSender.spigot().sendMessage(msg);
return false;
}
}
}else if (strings.length == 1) {
ToolBelt tb = new ToolBelt(plugin);
TextComponent msg;
switch (strings[0]) {
case "canStealPearls":
msg = tb.sendAsPlugin("Value of 'canStealPearls' is " + main.settings.get("canStealPearls"));
commandSender.spigot().sendMessage(msg);
break;
case "enabled":
msg = tb.sendAsPlugin("Value of 'enabled' is " + main.settings.get("enabled"));
case 1 -> {
if (options.contains(strings[0])) {
msg = tb.sendAsPlugin(ChatColor.YELLOW + strings[0] + ChatColor.WHITE + ": " + (main.settings.get(strings[0]) ? ChatColor.GREEN : ChatColor.RED) + main.settings.get(strings[0]));
commandSender.spigot().sendMessage(msg);
break;
case "disablePostTeleportFallDamage":
msg = tb.sendAsPlugin("Value of 'disablePostTeleportFallDamage' is " + main.settings.get("disablePostTeleportFallDamage"));
return true;
} else if (Objects.equals(strings[0], "*")) {
msg = tb.sendAsPlugin("All Rules:");
commandSender.spigot().sendMessage(msg);
break;
default:
for (Map.Entry<String, Boolean> rule : main.settings.entrySet()) {
msg = tb.sendAsPlugin(ChatColor.YELLOW + rule.getKey() + ChatColor.WHITE + ": " + (rule.getValue() ? ChatColor.GREEN : ChatColor.RED) + rule.getValue());
commandSender.spigot().sendMessage(msg);
}
}else {
msg = tb.sendAsPlugin(ChatColor.RED + "Rule '" + strings[0] + "' not found");
commandSender.spigot().sendMessage(msg);
return false;
}
}
}else {
commandSender.sendMessage(ChatColor.RED + "Usage: /sep <rule> <value>");
default -> commandSender.sendMessage(ChatColor.RED + "Usage: /sep <rule> [value]");
}
return true;
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cloud.thehsi.sharedenderpearls.Crafting;

import cloud.thehsi.sharedenderpearls.Main;
import cloud.thehsi.sharedenderpearls.ToolBelt;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;

public class HeadToPearl implements Listener {
Plugin plugin;
Main main;
ToolBelt toolBelt;
ShapedRecipe recipe;

public HeadToPearl(Plugin plugin, Main main) {
this.plugin = plugin;
this.main = main;
this.toolBelt = new ToolBelt(plugin);
ItemStack customItem = new ItemStack(Material.ENDER_PEARL, 4); // Change this to your desired item

NamespacedKey key = new NamespacedKey(this.plugin, "head_to_pearl");

// Create a new ShapedRecipe with the custom item
recipe = new ShapedRecipe(key, customItem);

// Define the recipe pattern (shape) and ingredients
recipe.shape("0P0", "PHP", "0P0");
recipe.setIngredient('0', Material.AIR);
recipe.setIngredient('H', Material.PLAYER_HEAD);
recipe.setIngredient('P', Material.ENDER_PEARL);

// Add the recipe to the server
if (main.settings.get("canBeCrafted")) this.plugin.getServer().addRecipe(recipe);
Bukkit.getScheduler().runTaskTimer(this.plugin, () -> Bukkit.getScheduler().runTask(this.plugin, () -> {
if (!main.settings.get("canBeCrafted")) this.plugin.getServer().removeRecipe(key);
if (this.plugin.getServer().getRecipe(key) != null) return;
if (main.settings.get("canBeCrafted")) this.plugin.getServer().addRecipe(recipe);
}), 5, 5);
}

@EventHandler
public void onCraft(CraftItemEvent event) {
if ((((ShapedRecipe) event.getRecipe()).getKey().getKey().equals("head_to_pearl"))) {
for (ItemStack item : event.getInventory().getMatrix()) {
if (item == null) continue;
if (item.getType() != Material.PLAYER_HEAD) continue;
SkullMeta skullMeta = (SkullMeta) item.getItemMeta();
if (skullMeta == null) continue;
if (skullMeta.getOwningPlayer() == null) continue;
if (skullMeta.getOwningPlayer().getPlayer() == null) continue;
if (event.getCurrentItem() == null) continue;
ItemMeta itemMeta = event.getCurrentItem().getItemMeta();
ItemStack itemStack = new ItemStack(Material.ENDER_PEARL);
if (itemMeta == null) continue;
itemMeta.getPersistentDataContainer().set(toolBelt.key("bind"), PersistentDataType.STRING, skullMeta.getOwningPlayer().getPlayer().getName());
itemMeta.setDisplayName(ChatColor.DARK_AQUA + "Bound Ender Pearl");
List<String> l = new ArrayList<>();
l.add(ChatColor.GOLD + "Ender Pearl bound to: " + skullMeta.getOwningPlayer().getPlayer().getDisplayName());
itemMeta.setLore(l);
itemStack.setItemMeta(itemMeta);
itemStack.addUnsafeEnchantment(Enchantment.LOYALTY, 1);
itemStack.setAmount(4);
event.setCurrentItem(itemStack);
if (main.settings.get("keepHeadAfterCrafting")) item.setAmount(item.getAmount()+1);
}
}
}
}
Loading

0 comments on commit 5548cad

Please sign in to comment.