added repair and unbreakable commands

This commit is contained in:
newt_00 2025-02-24 18:49:32 -05:00
parent e20ca91637
commit fa38a0f2d2
59 changed files with 174 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,7 @@
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/CoswayUtil.main.iml" filepath="$PROJECT_DIR$/.idea/modules/CoswayUtil.main.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/CoswayUtil.main.iml" filepath="$PROJECT_DIR$/.idea/modules/CoswayUtil.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/com.newt-tech.CoswayUtil.main.iml" filepath="$PROJECT_DIR$/.idea/modules/com.newt-tech.CoswayUtil.main.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -11,4 +11,8 @@
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module> </module>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>PAPER</platformType>
<platformType>ADVENTURE</platformType>
</autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion>
</configuration>
</facet>
</component>
</module>

Binary file not shown.

View File

@ -38,3 +38,11 @@ commands:
description: "opens block shop" description: "opens block shop"
usage: "/blockshop" usage: "/blockshop"
permission: CoswayUtil.shop permission: CoswayUtil.shop
unbreakable:
description: Makes the held tool unbreakable.
usage: /unbreakable
permission: coswayutil.unbreakable
repair:
description: Repairs the held tool to full durability.
usage: /repair
permission: coswayutil.repair

View File

@ -38,11 +38,11 @@ public class BlackholeEffect extends BukkitRunnable {
for (Entity nearbyEntity : nearbyEntities) { for (Entity nearbyEntity : nearbyEntities) {
if (nearbyEntity instanceof Monster && nearbyEntity != entity) { if (nearbyEntity instanceof Monster && nearbyEntity != entity) {
pullEntityTowards(nearbyEntity, blackholeLocation); pullEntityTowards(nearbyEntity, blackholeLocation);
pullTimer.putIfAbsent(nearbyEntity, 0); pullTimer.putIfAbsent(nearbyEntity, Integer.valueOf(0));
} }
} }
pullTimer.replaceAll((mob, time) -> time + 1); pullTimer.replaceAll((mob, time) -> (Integer) (time + 1));
Iterator<Map.Entry<Entity, Integer>> iterator = pullTimer.entrySet().iterator(); Iterator<Map.Entry<Entity, Integer>> iterator = pullTimer.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@ -68,6 +68,7 @@ public class BlackholeEffect extends BukkitRunnable {
} }
}.runTaskTimer(plugin, 0, 1); }.runTaskTimer(plugin, 0, 1);
iterator.remove(); iterator.remove();
removeEntityFromAllReferences(entity);
} }
} }
} }
@ -75,7 +76,10 @@ public class BlackholeEffect extends BukkitRunnable {
} }
} }
private void removeEntityFromAllReferences(Entity entity) {
pullTimer.remove(entity);
entity.remove();
}
private void pullEntityTowards(Entity entity, Location targetLocation) { private void pullEntityTowards(Entity entity, Location targetLocation) {
Vector direction = targetLocation.toVector().subtract(entity.getLocation().toVector()).normalize(); Vector direction = targetLocation.toVector().subtract(entity.getLocation().toVector()).normalize();
entity.setVelocity(direction.multiply(0.3)); entity.setVelocity(direction.multiply(0.3));

View File

@ -1,5 +1,6 @@
package CoswayUtil; package CoswayUtil;
import io.papermc.paper.datacomponent.item.Unbreakable;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -114,6 +115,10 @@ public final class CoswayUtil extends JavaPlugin implements Listener {
getServer().getPluginManager().registerEvents(new LaunchStick(this), this); getServer().getPluginManager().registerEvents(new LaunchStick(this), this);
new FireflySimulator(this); new FireflySimulator(this);
registration("FireFlies"); registration("FireFlies");
getCommand("unbreakable").setExecutor(new UnbreakableCommand());
registration("Unbreakable Command");
getCommand("repair").setExecutor(new RepairCommand());
registration("Repair Command");
//getServer().getPluginManager().registerEvents(new FireflySimulator(this), this); //getServer().getPluginManager().registerEvents(new FireflySimulator(this), this);
new BukkitRunnable() { new BukkitRunnable() {

View File

@ -0,0 +1,64 @@
package CoswayUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class RepairCommand implements CommandExecutor {
private static final Set<Material> REPAIRABLE_TOOLS = new HashSet<>(Arrays.asList(
Material.WOODEN_PICKAXE, Material.STONE_PICKAXE, Material.IRON_PICKAXE, Material.GOLDEN_PICKAXE, Material.DIAMOND_PICKAXE, Material.NETHERITE_PICKAXE,
Material.WOODEN_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLDEN_AXE, Material.DIAMOND_AXE, Material.NETHERITE_AXE,
Material.WOODEN_SHOVEL, Material.STONE_SHOVEL, Material.IRON_SHOVEL, Material.GOLDEN_SHOVEL, Material.DIAMOND_SHOVEL, Material.NETHERITE_SHOVEL,
Material.WOODEN_SWORD, Material.STONE_SWORD, Material.IRON_SWORD, Material.GOLDEN_SWORD, Material.DIAMOND_SWORD, Material.NETHERITE_SWORD,
Material.WOODEN_HOE, Material.STONE_HOE, Material.IRON_HOE, Material.GOLDEN_HOE, Material.DIAMOND_HOE, Material.NETHERITE_HOE,
Material.FISHING_ROD, Material.SHEARS
));
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command!");
return true;
}
Player player = (Player) sender;
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == Material.AIR) {
player.sendMessage(ChatColor.RED + "You must be holding a tool to repair it!");
return true;
}
if (!REPAIRABLE_TOOLS.contains(item.getType())) {
player.sendMessage(ChatColor.RED + "That item is not a valid tool!");
return true;
}
ItemMeta meta = item.getItemMeta();
if (meta instanceof Damageable) {
Damageable damageable = (Damageable) meta;
if (damageable.getDamage() == 0) {
player.sendMessage(ChatColor.YELLOW + "This tool is already at full durability!");
return true;
}
damageable.setDamage(0);
item.setItemMeta((ItemMeta) damageable);
player.sendMessage(ChatColor.GREEN + "Your tool has been fully repaired!");
}
return true;
}
}

View File

@ -0,0 +1,61 @@
package CoswayUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class UnbreakableCommand implements CommandExecutor {
private static final Set<Material> VALID_TOOLS = new HashSet<>(Arrays.asList(
Material.WOODEN_PICKAXE, Material.STONE_PICKAXE, Material.IRON_PICKAXE, Material.GOLDEN_PICKAXE, Material.DIAMOND_PICKAXE, Material.NETHERITE_PICKAXE,
Material.WOODEN_AXE, Material.STONE_AXE, Material.IRON_AXE, Material.GOLDEN_AXE, Material.DIAMOND_AXE, Material.NETHERITE_AXE,
Material.WOODEN_SHOVEL, Material.STONE_SHOVEL, Material.IRON_SHOVEL, Material.GOLDEN_SHOVEL, Material.DIAMOND_SHOVEL, Material.NETHERITE_SHOVEL,
Material.WOODEN_SWORD, Material.STONE_SWORD, Material.IRON_SWORD, Material.GOLDEN_SWORD, Material.DIAMOND_SWORD, Material.NETHERITE_SWORD,
Material.WOODEN_HOE, Material.STONE_HOE, Material.IRON_HOE, Material.GOLDEN_HOE, Material.DIAMOND_HOE, Material.NETHERITE_HOE,
Material.FISHING_ROD, Material.SHEARS
));
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command!");
return true;
}
Player player = (Player) sender;
ItemStack item = player.getInventory().getItemInMainHand();
if (item.getType() == Material.AIR) {
player.sendMessage(ChatColor.RED + "You must be holding a tool to make it unbreakable!");
return true;
}
if (!VALID_TOOLS.contains(item.getType())) {
player.sendMessage(ChatColor.RED + "That item is not a valid tool!");
return true;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) return true;
if (meta.isUnbreakable()) {
player.sendMessage(ChatColor.YELLOW + "This tool is already unbreakable!");
return true;
}
meta.setUnbreakable(true);
item.setItemMeta(meta);
player.sendMessage(ChatColor.GREEN + "Your tool has been made unbreakable!");
return true;
}
}

View File

@ -38,3 +38,11 @@ commands:
description: "opens block shop" description: "opens block shop"
usage: "/blockshop" usage: "/blockshop"
permission: CoswayUtil.shop permission: CoswayUtil.shop
unbreakable:
description: Makes the held tool unbreakable.
usage: /unbreakable
permission: coswayutil.unbreakable
repair:
description: Repairs the held tool to full durability.
usage: /repair
permission: coswayutil.repair