Skip to content

Commit

Permalink
Added lots of stuff
Browse files Browse the repository at this point in the history
impliment CMD to perform command on MedKit/Bandage
added option to toggle whther the command it done or not
added option to toggle if command is Console Command or not
added configurable lore (Will improve in a later update)
made the Bandages/MedKits glow when crafted

YW Floris, much loves bro
  • Loading branch information
xsmeths committed May 8, 2021
1 parent c3286f8 commit 6324b7f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 21 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>smeths.and.rhetorical</groupId>
<artifactId>MedCraft</artifactId>
<version>1.3.5.3</version>
<version>1.3.5.4</version>

<name>MedCraft</name>
<url>https://www.spigotmc.org/resources/bandagecraft.6760</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.smeths.and.rhetorical.ItemManager.ItemLoader;
import me.smeths.and.rhetorical.MedCraft;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
Expand All @@ -26,12 +27,12 @@ public BandageHandler(final Player p) {
}
bandagingPlayers.put(p, new BukkitRunnable()
{
Location position = p.getLocation();
final Location position = p.getLocation();
final int total = 60;
int progress = 0;
int duration = 20 * MedCraft.getPlugin().getConfig().getInt("Bandage.Regen-Time");
int amplifier = MedCraft.getPlugin().getConfig().getInt("Bandage.Regen-Amplifier");
int multiplier = MedCraft.getPlugin().getConfig().getInt("Bandage.Warmup-Speed");
final int duration = 20 * MedCraft.getPlugin().getConfig().getInt("Bandage.Regen-Time");
final int amplifier = MedCraft.getPlugin().getConfig().getInt("Bandage.Regen-Amplifier");
final int multiplier = MedCraft.getPlugin().getConfig().getInt("Bandage.Warmup-Speed");

public void cancel()
{
Expand All @@ -41,17 +42,23 @@ public void run()
{

boolean cancelled = p.getLocation().distance(this.position) > 0.75D;
if ((this.progress > 60) || (cancelled))
if ((this.progress > total) || (cancelled))
{
if (cancelled) {
p.getInventory().addItem(ItemLoader.getBandageItem());
}
BandageHandler.bandagingPlayers.remove(p);
cancel();
} else if (this.progress == 60) {
if (p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue())
} else if (this.progress == total) {
if (MedCraft.getPlugin().getConfig().getBoolean("Bandage.PerformCMD") == true && MedCraft.getPlugin().getConfig().getBoolean("Bandage.ConsoleCMD") == true && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.valueOf(MedCraft.getPlugin().getConfig().get("Bandage.CMD")).replace("[playername]", p.getName()));
} else if (MedCraft.getPlugin().getConfig().getBoolean("Bandage.PerformCMD") == true && MedCraft.getPlugin().getConfig().getBoolean("Bandage.ConsoleCMD") == false && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
Bukkit.dispatchCommand(p.getPlayer(),String.valueOf(MedCraft.getPlugin().getConfig().get("Bandage.CMD")).replace("[playername]", p.getName()));
} else if (MedCraft.getPlugin().getConfig().getBoolean("Bandage.PerformCMD") == false && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
} else {
p.getInventory().addItem(ItemLoader.getBandageItem());
BandageHandler.bandagingPlayers.remove(p);
cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import me.smeths.and.rhetorical.ItemManager.ItemLoader;
import me.smeths.and.rhetorical.MedCraft;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
Expand Down Expand Up @@ -52,9 +53,15 @@ public void run()
MedKitHandler.MedKitPlayers.remove(p);
cancel();
} else if (this.progress == 60) {
if (p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue())
if (MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") == true && MedCraft.getPlugin().getConfig().getBoolean("MedKit.ConsoleCMD") == true && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), String.valueOf(MedCraft.getPlugin().getConfig().get("MedKit.CMD")).replace("[playername]", p.getName()));
} else if (MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") == true && MedCraft.getPlugin().getConfig().getBoolean("MedKit.ConsoleCMD") == false && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
Bukkit.dispatchCommand(p.getPlayer(),String.valueOf(MedCraft.getPlugin().getConfig().get("MedKit.CMD")).replace("[playername]", p.getName()));
} else if (MedCraft.getPlugin().getConfig().getBoolean("MedKit.PerformCMD") == false && p.getHealth() < Objects.requireNonNull(p.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getValue()) {
p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, duration, amplifier));
} else {
p.getInventory().addItem(ItemLoader.getMedKitItem());
MedKitHandler.MedKitPlayers.remove(p);
cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;

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

public class ItemLoader {
private Plugin medCraft = MedCraft.getPlugin();
private static ItemLoader instance;
Expand Down Expand Up @@ -48,12 +53,16 @@ public static ItemStack getBandageItem() {
}

private void setupBandageItem() {
List<String> Bandagelore = new ArrayList<String>();
String BandageName = MedCraft.getPlugin().getConfig().getString("Bandage.Name");
bandageItem = new ItemStack(Material.getMaterial(MedCraft.getPlugin().getConfig().getString("Bandage.Material")), 1);
ItemMeta BandageMeta = bandageItem.getItemMeta();
BandageMeta.setCustomModelData(medCraft.getConfig().getInt("Bandage.ModelData"));
BandageMeta.setDisplayName(ChatColor.RESET + ChatColor.translateAlternateColorCodes('&',BandageName));
this.bandageItem.setItemMeta(BandageMeta);
BandageMeta.addEnchant(Enchantment.DURABILITY,1,true);
BandageMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
Bandagelore.add(ChatColor.RESET + ChatColor.translateAlternateColorCodes('&',MedCraft.getPlugin().getConfig().getString("Bandage.Lore-1")));
bandageItem.setItemMeta(BandageMeta);
}
private void setupCraftedBandageItem() {
craftedbandageItem = new ItemStack(Material.getMaterial(MedCraft.getPlugin().getConfig().getString("Bandage.Material")), medCraft.getConfig().getInt("Bandage.Result-Amount"));
Expand All @@ -75,11 +84,16 @@ private void setupBandageRecipe() {
Bukkit.addRecipe(Bandagerecipe);
}
private void setupMedKitItem() {
List<String> Medkitlore = new ArrayList<String>();
String MedKitName = MedCraft.getPlugin().getConfig().getString("MedKit.Name");
MedKitItem = new ItemStack(Material.getMaterial(MedCraft.getPlugin().getConfig().getString("MedKit.Material")),1 );
ItemMeta MedKitMeta = MedKitItem.getItemMeta();
MedKitMeta.setCustomModelData(medCraft.getConfig().getInt("MedKit.ModelData"));
MedKitMeta.setDisplayName(ChatColor.RESET + ChatColor.translateAlternateColorCodes('&',MedKitName));
MedKitMeta.addEnchant(Enchantment.DURABILITY,1,true);
MedKitMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
Medkitlore.add(ChatColor.RESET + ChatColor.translateAlternateColorCodes('&',MedCraft.getPlugin().getConfig().getString("MedKit.Lore-1")));
MedKitMeta.setLore(Medkitlore);
MedKitItem.setItemMeta(MedKitMeta);
}
private void setupCraftedMedKitItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public void onPlayerUseMedKit(PlayerInteractEvent e) {
int heldslot = p.getInventory().getHeldItemSlot();
p.getInventory().setItem(heldslot, new ItemStack(Material.AIR));
p.updateInventory();
new MedKitHandler(p); return;
new MedKitHandler(p);
return;
}
if (i.getAmount() >= 2 && p.hasPermission("medkit.use")) {
i.setAmount(i.getAmount() - 1);
Expand Down
11 changes: 9 additions & 2 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Bandage:
Material: PAPER
Warmup-Speed: 1
Warmup-Speed: 2
Result-Amount: 2
movecancel-threshhold: 0.75D
ModelData: 16
Name: '&4✚&fBandage&4✚'
Lore-1: '&6Right/Left click to use this MedKit'
Regen-Time: 3
Regen-Amplifier: 1
Crafting-Material-top-left: AIR
Expand All @@ -16,12 +16,16 @@ Bandage:
Crafting-Material-bottom-left: AIR
Crafting-Material-bottom-middle: PAPER
Crafting-Material-bottom-right: AIR
PerformCMD: false
ConsoleCMD: true
CMD: 'tell [playername] your server admin did not configure this plugin'
MedKit:
Material: PAPER
Warmup-Speed: 1
Result-Amount: 1
ModelData: 18
Name: '&c✚&fMedKit&c✚'
Lore-1: '&6Right/Left click to use this MedKit'
Regen-Time: 6
Regen-Amplifier: 2
Crafting-Material-top-left: PAPER
Expand All @@ -33,3 +37,6 @@ MedKit:
Crafting-Material-bottom-left: PAPER
Crafting-Material-bottom-middle: PAPER
Crafting-Material-bottom-right: PAPER
PerformCMD: false
ConsoleCMD: true
CMD: 'tell [playername] your server admin did not configure this plugin'
16 changes: 10 additions & 6 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: MedCraft
main: me.smeths.and.rhetorical.MedCraft
author: smeths&rhetorical
version: 1.3.5.3
version: 1.3.5.4
api-version: 1.13
commands:
MedCraft:
description: MedCraft Command!
usage: /MedCraft
aliases: [meds]
permissions:
bandage.craft:
default: op
bandage.use:
default: op
medkit.craft:
default: op
medkit.user:
default: op

0 comments on commit 6324b7f

Please sign in to comment.