9
0
mirror of https://github.com/Auxilor/Reforges.git synced 2025-12-29 03:49:11 +00:00

Initial commit

This commit is contained in:
Auxilor
2021-08-12 15:02:51 +01:00
commit 3759290682
29 changed files with 2133 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
group 'com.willfp'
version rootProject.version
dependencies {
compileOnly 'org.spigotmc:spigot-api:1.16.4-R0.1-SNAPSHOT'
}

View File

@@ -0,0 +1,48 @@
package com.willfp.reforges;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.reforges.commands.CommandReforge;
import com.willfp.reforges.display.ReforgesDisplay;
import lombok.Getter;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
public class ReforgesPlugin extends EcoPlugin {
/**
* Instance of Reforges.
*/
@Getter
private static ReforgesPlugin instance;
/**
* Internal constructor called by bukkit on plugin load.
*/
public ReforgesPlugin() {
super(0, 12412, "&#00ff00");
instance = this;
}
@Override
protected List<Listener> loadListeners() {
return Arrays.asList(
);
}
@Override
protected List<PluginCommand> loadPluginCommands() {
return Arrays.asList(
new CommandReforge(this)
);
}
@Override
protected @Nullable DisplayModule createDisplayModule() {
return new ReforgesDisplay(this);
}
}

View File

@@ -0,0 +1,27 @@
package com.willfp.reforges.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.reforges.gui.ReforgeGUI;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class CommandReforge extends PluginCommand {
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandReforge(@NotNull final EcoPlugin plugin) {
super(plugin, "reforge", "reforges.command.reforge", true);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
ReforgeGUI.getMenu().open((Player) sender);
};
}
}

View File

@@ -0,0 +1,26 @@
package com.willfp.reforges.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import org.jetbrains.annotations.NotNull;
public class CommandReload extends Subcommand {
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandReload(@NotNull final EcoPlugin plugin) {
super(plugin, "reload", "reforges.command.reload", false);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
this.getPlugin().reload();
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
};
}
}

View File

@@ -0,0 +1,28 @@
package com.willfp.reforges.config;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.config.yaml.YamlExtendableConfig;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class ReforgeConfig extends YamlExtendableConfig {
/**
* The name of the config.
*/
@Getter
private final String name;
/**
* Instantiate a new config for a reforge.
*
* @param name The name of the config.
* @param source The provider of the reforge.
* @param plugin Instance of reforges.
*/
public ReforgeConfig(@NotNull final String name,
@NotNull final Class<?> source,
@NotNull final EcoPlugin plugin) {
super(name, true, plugin, source, "reforges/");
this.name = name;
}
}

View File

@@ -0,0 +1,23 @@
package com.willfp.reforges.display;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.display.DisplayPriority;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class ReforgesDisplay extends DisplayModule {
/**
* Create weapons display.
*
* @param plugin Instance of Reforges.
*/
public ReforgesDisplay(@NotNull final EcoPlugin plugin) {
super(plugin, DisplayPriority.HIGHEST);
}
@Override
protected void display(@NotNull final ItemStack itemStack,
@NotNull final Object... args) {
}
}

View File

@@ -0,0 +1,106 @@
package com.willfp.reforges.gui;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.FillerMask;
import com.willfp.eco.core.gui.slot.Slot;
import com.willfp.eco.core.items.builder.ItemStackBuilder;
import com.willfp.reforges.ReforgesPlugin;
import lombok.Getter;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
@UtilityClass
public class ReforgeGUI {
/**
* The reforge GUI.
*/
@Getter
private static Menu menu;
/**
* Update the GUI.
*
* @param plugin The plugin.
*/
@ConfigUpdater
public static void update(@NotNull final EcoPlugin plugin) {
menu = Menu.builder(5)
.setTitle("Reforge Item")
.setMask(
new FillerMask(
Material.BLACK_STAINED_GLASS_PANE,
"011111110",
"011101110",
"011101110",
"011111110",
"011101110"
)
).modfiy(builder -> {
Slot slot = Slot.builder(
new ItemStackBuilder(Material.RED_STAINED_GLASS_PANE)
.setDisplayName("&r")
.build()
).setModifier((player, menu, previous) -> {
if (menu.getCaptiveItems(player).isEmpty()) {
previous.setType(Material.RED_STAINED_GLASS_PANE);
} else {
previous.setType(Material.LIME_STAINED_GLASS_PANE);
}
}).build();
for (int i = 1; i <= 5; i++) {
builder.setSlot(i, 1, slot);
builder.setSlot(i, 9, slot);
}
}).setSlot(2, 5,
Slot.builder()
.setCaptive()
.build()
).setSlot(3, 5,
Slot.builder(new ItemStack(Material.ANVIL))
.setModifier((player, menu, previous) -> {
ItemMeta meta = previous.getItemMeta();
if (meta == null) {
return;
}
if (menu.getCaptiveItems(player).isEmpty()) {
meta.setDisplayName(plugin.getConfigYml().getString("gui.no-item.name"));
meta.setLore(plugin.getConfigYml().getStrings("gui.no-item.lore"));
} else {
meta.setDisplayName(plugin.getConfigYml().getString("gui.available.name"));
meta.setLore(plugin.getConfigYml().getStrings("gui.available.lore"));
}
previous.setItemMeta(meta);
})
.onLeftClick((event, slot, menu) -> {
Player player = (Player) event.getWhoClicked();
ItemStack toReforge = menu.getCaptiveItems(player).isEmpty() ? null : menu.getCaptiveItems(player).get(0);
if (toReforge == null) {
return;
}
player.sendMessage("reforged");
}).build()
)
.setSlot(5, 5,
Slot.builder(
new ItemStackBuilder(Material.BARRIER)
.setDisplayName("&cClose")
.build()
).onLeftClick((event, slot) -> {
event.getWhoClicked().closeInventory();
}).build()
)
.build();
}
static {
update(ReforgesPlugin.getInstance());
}
}

View File

@@ -0,0 +1,101 @@
package com.willfp.reforges.reforges;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.Prerequisite;
import com.willfp.reforges.ReforgesPlugin;
import com.willfp.reforges.config.ReforgeConfig;
import com.willfp.reforges.reforges.meta.ReforgeTarget;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public abstract class Reforge {
/**
* Instance of Reforges for reforges to be able to access.
*/
@Getter(AccessLevel.PROTECTED)
private final EcoPlugin plugin = ReforgesPlugin.getInstance();
/**
* The key to store reforges in meta.
*/
@Getter
private final String key;
/**
* The reforges config.
*/
@Getter
private final ReforgeConfig config;
/**
* If the reforge is enabled.
*/
@Getter
private boolean enabled;
/**
* Create a new Reforge.
*
* @param key The key name of the reforge..
* @param prerequisites Optional {@link Prerequisite}s that must be met.
*/
protected Reforge(@NotNull final String key,
@NotNull final Prerequisite... prerequisites) {
this.key = key;
this.config = new ReforgeConfig(this.getKey(), this.getClass(), this.plugin);
if (!Prerequisite.areMet(prerequisites)) {
return;
}
Reforges.addNewReforge(this);
this.update();
}
/**
* Update the reforge based off config values.
* This can be overridden but may lead to unexpected behavior.
*/
public void update() {
enabled = config.getBool("enabled");
postUpdate();
}
protected void postUpdate() {
// Unused as some talismans may have postUpdate tasks, however most won't.
}
/**
* Get the reforge target.
*/
public abstract ReforgeTarget getTarget();
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Reforge reforge)) {
return false;
}
return this.getKey().equals(reforge.getKey());
}
@Override
public int hashCode() {
return Objects.hash(this.getKey());
}
@Override
public String toString() {
return "Reforge{"
+ this.getKey()
+ "}";
}
}

View File

@@ -0,0 +1,84 @@
package com.willfp.reforges.reforges;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
@SuppressWarnings({"unused", "checkstyle:JavadocVariable"})
public class Reforges {
public static final String CONFIG_LOCATION = "config.";
public static final String OBTAINING_LOCATION = "obtaining.";
public static final String GENERAL_LOCATION = "general-config.";
private static final BiMap<String, Reforge> BY_KEY = HashBiMap.create();
/**
* Get all registered {@link Reforge}s.
*
* @return A list of all {@link Reforge}s.
*/
public static Set<Reforge> values() {
return ImmutableSet.copyOf(BY_KEY.values());
}
/**
* Get {@link String}s for all registered {@link Reforge}s.
*
* @return A list of all {@link Reforge}s.
*/
public static Set<String> keySet() {
return ImmutableSet.copyOf(BY_KEY.keySet());
}
/**
* Get {@link Reforge} matching key.
*
* @param key The key to search for.
* @return The matching {@link Reforge}, or null if not found.
*/
public static Reforge getByKey(@Nullable final String key) {
if (key == null) {
return null;
}
return BY_KEY.get(key);
}
/**
* Update all {@link Reforge}s.
*/
@ConfigUpdater
public static void update() {
for (Reforge reforge : new HashSet<>(values())) {
reforge.update();
}
}
/**
* Add new {@link Reforge} to Reforges.
* <p>
* Only for internal use, reforges are automatically added in the constructor.
*
* @param reforge The {@link Reforge} to add.
*/
public static void addNewReforge(@NotNull final Reforge reforge) {
BY_KEY.remove(reforge.getKey());
BY_KEY.put(reforge.getKey(), reforge);
}
/**
* Remove {@link Reforge} from Reforges.
*
* @param reforge The {@link Reforge} to remove.
*/
public static void removeReforge(@NotNull final Reforge reforge) {
BY_KEY.remove(reforge.getKey());
}
}

View File

@@ -0,0 +1,139 @@
package com.willfp.reforges.reforges.meta;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.reforges.ReforgesPlugin;
import lombok.Getter;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
public class ReforgeTarget {
/**
* Target containing the materials from all other targets.
*/
public static final ReforgeTarget ALL = new ReforgeTarget("all", new HashSet<>());
/**
* Melee weapons.
*/
public static final ReforgeTarget MELEE = new ReforgeTarget("melee");
/**
* Armor.
*/
public static final ReforgeTarget ARMOR = new ReforgeTarget("armor");
/**
* Trident.
*/
public static final ReforgeTarget TRIDENT = new ReforgeTarget("trident");
/**
* Bows.
*/
public static final ReforgeTarget BOW = new ReforgeTarget("bow");
/**
* All registered targets.
*/
private static final Set<ReforgeTarget> REGISTERED = new HashSet<>();
static {
REGISTERED.add(ALL);
REGISTERED.add(MELEE);
REGISTERED.add(ARMOR);
REGISTERED.add(TRIDENT);
REGISTERED.add(BOW);
update(ReforgesPlugin.getInstance());
}
/**
* The name of the target.
*/
@Getter
private final String name;
/**
* The materials of the target.
*/
@Getter
private final Set<Material> materials;
/**
* Create new target.
*
* @param name The name of the target.
* @param materials The items for the target.
*/
public ReforgeTarget(@NotNull final String name,
@NotNull final Set<Material> materials) {
this.name = name;
materials.removeIf(Objects::isNull);
this.materials = materials;
}
/**
* Create new target.
*
* @param name The name of the target.
*/
public ReforgeTarget(@NotNull final String name) {
this.name = name;
this.materials = new HashSet<>();
update();
}
/**
* Update the configs.
*/
public void update() {
this.materials.clear();
this.materials.addAll(ReforgesPlugin.getInstance().getConfigYml().getStrings("targets." + name, false).stream().map(
s -> Material.getMaterial(s.toUpperCase())
).collect(Collectors.toSet()));
}
/**
* Get ReforgeTarget matching name.
*
* @param name The name to search for.
* @return The matching ReforgeTarget, or null if not found.
*/
public static ReforgeTarget getByName(@NotNull final String name) {
Optional<ReforgeTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
return matching.orElse(null);
}
/**
* Update all targets.
*
* @param plugin Instance of Reforges.
*/
@ConfigUpdater
public static void update(@NotNull final ReforgesPlugin plugin) {
ALL.materials.clear();
for (ReforgeTarget reforgeTarget : REGISTERED) {
if (reforgeTarget.name.equals("all")) {
continue;
}
reforgeTarget.update();
ALL.materials.addAll(reforgeTarget.materials);
}
}
/**
* Get all targets.
*
* @return A set of all targets.
*/
public static Set<ReforgeTarget> values() {
return ImmutableSet.copyOf(REGISTERED);
}
}

View File

@@ -0,0 +1,15 @@
package com.willfp.reforges.reforges.reforges;
import com.willfp.reforges.reforges.Reforge;
import com.willfp.reforges.reforges.meta.ReforgeTarget;
public class ReforgeSharp extends Reforge {
public ReforgeSharp() {
super("sharp");
}
@Override
public ReforgeTarget getTarget() {
return ReforgeTarget.MELEE;
}
}

View File

@@ -0,0 +1,97 @@
package com.willfp.reforges.reforges.util;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.reforges.ReforgesPlugin;
import com.willfp.reforges.reforges.Reforge;
import com.willfp.reforges.reforges.Reforges;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@UtilityClass
public class ReforgeUtils {
/**
* Instance of StatTrackers.
*/
private static final EcoPlugin PLUGIN = ReforgesPlugin.getInstance();
/**
* The key for storing the currently displayed stat.
*/
private static final NamespacedKey REFORGE_KEY = PLUGIN.getNamespacedKeyFactory().create("reforge");
/**
* Get reforge on an item.
*
* @param item The item to query.
* @return The found reforge, or null if none active.
*/
public static Reforge getReforge(@Nullable final ItemStack item) {
if (item == null) {
return null;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return null;
}
return getReforge(meta);
}
/**
* Get reforge on an item.
*
* @param meta The item to query.
* @return The found reforge, or null if none active.
*/
public static Reforge getReforge(@Nullable final ItemMeta meta) {
if (meta == null) {
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
String active = container.get(REFORGE_KEY, PersistentDataType.STRING);
return Reforges.getByKey(active);
}
/**
* Set reforge on an item.
*
* @param item The item.
* @param reforge The reforge.
*/
public static void setReforge(@NotNull final ItemStack item,
@NotNull final Reforge reforge) {
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return;
}
setReforge(meta, reforge);
item.setItemMeta(meta);
}
/**
* Set reforge on an item.
*
* @param meta The meta.
* @param reforge The reforge.
*/
public static void setReforge(@NotNull final ItemMeta meta,
@NotNull final Reforge reforge) {
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(REFORGE_KEY, PersistentDataType.STRING, reforge.getKey());
}
}

View File

@@ -0,0 +1,76 @@
#
# Reforges
# by Auxilor
#
gui:
available:
name: "&aReforge Item"
lore:
- '&7Reforges the above item, giving'
- '&7it a random item modifier that'
- '&7boosts its stats.'
- ''
- '&7Cost'
- '&6\$%cost%'
- ''
- '&eClick to reforge!'
no-item:
name: "&eReforge Item"
lore:
- '&7Place an item above to reforge'
- '&7it! Reforging items adds a'
- '&7random modifier to the item that'
- '&7grants stat boosts'
reforge:
cost: 5000
targets:
melee:
- wooden_axe
- stone_axe
- iron_axe
- golden_axe
- diamond_axe
- netherite_axe
- wooden_sword
- stone_sword
- iron_sword
- golden_sword
- diamond_sword
- netherite_sword
trident:
- trident
bow:
- bow
- crossbow
armor:
- turtle_helmet
- leather_helmet
- chainmail_helmet
- iron_helmet
- golden_helmet
- diamond_helmet
- netherite_helmet
- leather_chestplate
- chainmail_chestplate
- iron_chestplate
- golden_chestplate
- diamond_chestplate
- netherite_chestplate
- leather_leggings
- chainmail_leggings
- iron_leggings
- golden_leggings
- diamond_leggings
- netherite_leggings
- leather_boots
- chainmail_boots
- iron_boots
- golden_boots
- diamond_boots
- netherite_boots

View File

@@ -0,0 +1,11 @@
messages:
prefix: "&#00ff00&lReforges&r &8» &r"
no-permission: "&cYou don't have permission to do this!"
not-player: "&cThis command must be run by a player"
invalid-command: "&cUnknown subcommand!"
reloaded: "Reloaded! (Restart if you're removed weapons!)"
needs-player: "&cYou must specify a player"
invalid-player: "&cInvalid player!"
needs-item: "&cYou must specify an item!"
invalid-item: "&cInvalid item!"
give-success: "Gave &a%item%&r to &a%recipient%"

View File

@@ -0,0 +1,42 @@
name: Reforges
version: ${projectVersion}
main: com.willfp.reforges.ReforgesPlugin
api-version: 1.16
authors: [ Auxilor ]
website: willfp.com
load: STARTUP
depend:
- eco
- ProtocolLib
commands:
reforges:
description: Base Command
permission: reforges.command.reforges
reforge:
description: Open reforge menu
permission: reforges.command.reforge
permissions:
reforges.*:
description: All reforges permissions
default: op
children:
reforges.command.*: true
reforges.command.*:
description: All commands
default: op
children:
reforges.command.reload: true
reforges.command.reforges: true
reforges.command.reforge: true
reforges.command.reload:
description: Allows reloading the config
default: op
reforges.command.reforges:
description: Allows the user of /reforges.
default: true
reforges.command.reforge:
description: Allows the user of /reforge.
default: op

View File

@@ -0,0 +1,10 @@
#
# Sharp Reforge
#
name: "&6Sharp"
enabled: true
description: "Deal &a3%&r more damage"
config:
multiplier: 1.03 # Damage multiplier