Skip to content

Commit

Permalink
[CORE] Ground Work for First menu being fully reimplemented
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfieheart <[email protected]>
  • Loading branch information
Wolfieheart committed Jan 3, 2025
1 parent 9d190a3 commit 503469c
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import io.github.rypofalem.armorstandeditor.devtools.Debug;

import io.github.rypofalem.armorstandeditor.language.Lang;
import io.github.rypofalem.armorstandeditor.metricshandler.MetricsHandler;
import io.github.rypofalem.armorstandeditor.playereditor.PlayerEditorManager;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
Expand All @@ -24,6 +28,7 @@ public final class ArmorStandEditorPlugin extends JavaPlugin {
// Classes
private static ArmorStandEditorPlugin instance;
private Debug debug = new Debug(this);
private Lang lang;
MetricsHandler metricsHandler;

// Server Software Check True/False
Expand All @@ -43,6 +48,7 @@ public final class ArmorStandEditorPlugin extends JavaPlugin {

String aseVersion;
String nmsVersion;
String languageFolderLocation = "lang/";
String editToolType;
String editToolName;
String editToolLore;
Expand Down Expand Up @@ -70,6 +76,10 @@ public final class ArmorStandEditorPlugin extends JavaPlugin {
String lockedTeam = "ASLocked";
String inUseTeam = "AS-InUse";

// Interconnectivity to other parts of the Plugin
PlayerEditorManager editorManager;
private NamespacedKey iconKey;

public ArmorStandEditorPlugin() {
instance = this;
}
Expand Down Expand Up @@ -115,6 +125,22 @@ public void onEnable() {
doScoreboardSetup();

//TODO: Readd Languages here!
updateConfig("", "config.yml");
updateConfig(languageFolderLocation, "de_DE.yml");
updateConfig(languageFolderLocation, "es_ES.yml");
updateConfig(languageFolderLocation, "fr_FR.yml");
updateConfig(languageFolderLocation, "ja_JP.yml");
updateConfig(languageFolderLocation, "nl_NL.yml");
updateConfig(languageFolderLocation, "pl_PL.yml");
updateConfig(languageFolderLocation, "pt_BR.yml");
updateConfig(languageFolderLocation, "ro_RO.yml");
updateConfig(languageFolderLocation, "ru_RU.yml");
updateConfig(languageFolderLocation, "test_NA.yml");
updateConfig(languageFolderLocation, "uk_UA.yml");
updateConfig(languageFolderLocation, "zh_CN.yml");

saveResource("lang/en_US.yml", true);
lang = new Lang(getLanguageConfig(), this);

// Get all the Configuration Options
coarseRotation = getCoarseConfig();
Expand Down Expand Up @@ -146,6 +172,12 @@ public void onEnable() {

// Do all the Metrics for BStats
metricsHandler = new MetricsHandler();
editorManager = new PlayerEditorManager(this);

// Registrations


getServer().getPluginManager().registerEvents(editorManager, this);

}

Expand All @@ -172,6 +204,13 @@ public static boolean isPaper() {
return false;
}
}

private void updateConfig(String folder, String config) {
if (!new File(getDataFolder() + File.separator + folder + config).exists()) {
saveResource(folder + config, false);
}
}

private void doNMSChecks(String nmsVersion) {
// Check if the Minecraft version is supported
warningMCVer = String.format("Mineacraft Version: %s", nmsVersion);
Expand Down Expand Up @@ -283,6 +322,7 @@ private void doPerWorldSupportSetup(boolean perWorldSupport){
public double getMinScaleConfig() { return getConfig().getDouble("minScaleValue"); }
public double getMaxScaleConfig() { return getConfig().getDouble("maxScaleValue"); }

public String getLanguageConfig(){ return getConfig().getString("lang"); }
public String getToolTypeConfig() { return getConfig().getString("tool");}
public String getToolNameConfig() { return getConfig().getString("editToolName");}
public String getToolLoreConfig(){ return getConfig().getString("toolLore", null); }
Expand All @@ -293,6 +333,18 @@ public List<?> getAllowedWorldListConfig(){
}


public Lang getLang() {
return this.lang;
}

public PlayerEditorManager getEditorManager() {
return this.editorManager;
}

public NamespacedKey getIconKey() {
if (iconKey == null) iconKey = new NamespacedKey(this, "command_icon");
return iconKey;

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.rypofalem.armorstandeditor.Utils;

public abstract class Utils {

public static final double FULL_CIRCLE = Math.PI * 2;

public static <T extends Enum<?>> String getEnumList(Class<T> enumType) {
return getEnumList(enumType, " | ");
}

public static <T extends Enum<?>> String getEnumList(Class<T> enumType, String delimiter) {
StringBuilder list = new StringBuilder();
boolean put = false;
for (Enum<?> e : enumType.getEnumConstants()) {
list.append(e.toString()).append(delimiter);
put = true;
}
if (put) list = new StringBuilder(list.substring(0, list.length() - delimiter.length()));
return list.toString();
}

public static double addAngle(double current, double angleChange) {
current += angleChange;
current = fixAngle(current, angleChange);
return current;
}

public static double subAngle(double current, double angleChange) {
current -= angleChange;
current = fixAngle(current, angleChange);
return current;
}

//clamps angle to 0 if it exceeds 2PI rad (360 degrees), is closer to 0 than angleChange value, or is closer to 2PI rad than 2PI rad - angleChange value.
private static double fixAngle(double angle, double angleChange) {
if (angle > FULL_CIRCLE) {
return 0;
}

if (angle > 0 && angle < angleChange && angle < angleChange / 2) {
return 0;
}

if (angle > FULL_CIRCLE - angle && angle > FULL_CIRCLE - (angleChange / 2)) {
return 0;
}

return angle;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package io.github.rypofalem.armorstandeditor.menu;

import io.github.rypofalem.armorstandeditor.api.events.editor.ArmorStandEditorOpenedEvent;
import io.github.rypofalem.armorstandeditor.playereditor.PlayerEditor;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.*;

import net.kyori.adventure.text.Component;

import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;

import static java.util.Objects.requireNonNull;

public class EquipmentMenu implements EditorMenu{

Inventory menuInv;
private ArmorStand armorStand;
private PlayerEditor pe;
static String menuName = "ArmorStand Eqiupment";
ItemStack helm, chest, pants, boots, rHand, lHand;

public EquipmentMenu(PlayerEditor pe, ArmorStand as){
this.pe = pe;
this.armorStand = as;
menuName = pe.plugin.getLang().getMessage("equiptitle", "menutitle");
menuInv = Bukkit.createInventory(this, 18, Component.text(menuName));
}

@Override
public void open() {
ArmorStandEditorOpenedEvent evt = new ArmorStandEditorOpenedEvent(pe.getPlayer(), this);
Bukkit.getPluginManager().callEvent(evt);
if(evt.isCancelled()) return;
fillInventory();
pe.getPlayer().openInventory(this.menuInv);
}

@Override
public ArmorStand getArmorStand() {
return this.armorStand;
}

@Override
public @NotNull Inventory getInventory() {
return menuInv;
}

private void fillInventory() {
menuInv.clear();
EntityEquipment equipment = armorStand.getEquipment();
ItemStack theHelmet = equipment.getHelmet();
ItemStack theChest = equipment.getChestplate();
ItemStack thePants = equipment.getLeggings();
ItemStack theFeetsies = equipment.getBoots();
ItemStack theRightHand = equipment.getItemInMainHand();
ItemStack theLeftHand = equipment.getItemInOffHand();
//equipment.clear();

ItemStack disabledSlot = new ItemStack(Material.BARRIER);
ItemMeta meta = disabledSlot.getItemMeta();
meta.displayName(Component.text(pe.plugin.getLang().getMessage("disabled", "warn")));
meta.getPersistentDataContainer().set(pe.plugin.getIconKey(), PersistentDataType.STRING, "ase icon");
disabledSlot.setItemMeta(meta);

ItemStack helmetIcon = createIcon(Material.LEATHER_HELMET, "helm");
ItemStack chestIcon = createIcon(Material.LEATHER_CHESTPLATE, "chest");
ItemStack pantsIcon = createIcon(Material.LEATHER_LEGGINGS, "pants");
ItemStack feetsiesIcon = createIcon(Material.LEATHER_BOOTS, "boots");
ItemStack rightHandIcon = createIcon(Material.WOODEN_SWORD, "rhand");
ItemStack leftHandIcon = createIcon(Material.SHIELD, "lhand");
ItemStack[] items = {
helmetIcon, chestIcon, pantsIcon, feetsiesIcon, rightHandIcon, leftHandIcon, disabledSlot, disabledSlot, disabledSlot,
theHelmet, theChest, thePants, theFeetsies, theRightHand, theLeftHand, disabledSlot, disabledSlot, disabledSlot
};
menuInv.setContents(items);

}

private ItemStack createIcon(Material mat, String slot) {
ItemStack icon = new ItemStack(mat);
ItemMeta meta = icon.getItemMeta();
meta.getPersistentDataContainer().set(pe.plugin.getIconKey(), PersistentDataType.STRING, "ase icon");
meta.displayName(Component.text(pe.plugin.getLang().getMessage("equipslot", "iconname", slot))); //equipslot.msg <option>
ArrayList<Component> loreList = new ArrayList<>();
loreList.add(Component.text(pe.plugin.getLang().getMessage("equipslot.description", "icondescription", slot))); //equioslot.description.msg <option>
meta.lore(loreList);
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.addItemFlags(ItemFlag.HIDE_ADDITIONAL_TOOLTIP);
icon.setItemMeta(meta);
return icon;
}

public void equipArmorstand() {
Map<EquipmentSlot, ItemStack> items = new EnumMap<>(EquipmentSlot.class);
items.put(EquipmentSlot.HEAD, menuInv.getItem(9));
items.put(EquipmentSlot.CHEST, menuInv.getItem(10));
items.put(EquipmentSlot.LEGS, menuInv.getItem(11));
items.put(EquipmentSlot.FEET, menuInv.getItem(12));
items.put(EquipmentSlot.HAND, menuInv.getItem(13));
items.put(EquipmentSlot.OFF_HAND, menuInv.getItem(14));

List<ItemStack> returnItems = new ArrayList<>();
EntityEquipment equipment = requireNonNull(armorStand.getEquipment());
if (!armorStand.isValid() || armorStand.isDead()) {
returnItems.addAll(items.values());
} else {
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack item = items.get(slot);
if (item == null || item.getType().isAir()) continue;
ItemStack oldItem = equipment.getItem(slot);
if (!oldItem.getType().isAir() && oldItem != null) {
returnItems.add(item);
} else {
equipment.setItem(slot, item);
}
}
}

Player player = pe.getPlayer();
for (ItemStack item : returnItems) {
if (item == null || item.getType().isAir()) continue;
for (ItemStack drop : player.getInventory().addItem(item).values()) {
player.getWorld().dropItem(player.getEyeLocation(), drop).setPickupDelay(0);
}
}

}

public static String getName() {
return menuName;
}


}
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package io.github.rypofalem.armorstandeditor.playereditor;

import io.github.rypofalem.armorstandeditor.ArmorStandEditorPlugin;
import org.bukkit.entity.Player;

import java.util.UUID;

//TODO: To be Refactored
public class PlayerEditor {

private UUID uuid;
public final ArmorStandEditorPlugin plugin;

public PlayerEditor(ArmorStandEditorPlugin plugin) {
public PlayerEditor(UUID uuid, ArmorStandEditorPlugin plugin) {
this.plugin = plugin;
this.uuid = uuid;
}

public PlayerEditorManager getPlayerEditorManager(){
return plugin.getEditorManager();
}

public PlayerEditorManager getManager(){
return plugin.editorManager;
public Player getPlayer() {
return plugin.getServer().getPlayer(getUUID());
}

public UUID getUUID() {
return uuid;
}
}
Loading

0 comments on commit 503469c

Please sign in to comment.