Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ repositories {
maven {
url "https://repo.oraxen.com/releases"
}
maven {
url "https://repo.nexomc.com/releases"
}
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT")
compileOnly 'io.th0rgal:oraxen:1.184.1'
compileOnly("com.nexomc:nexo:1.10.0")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.15")

implementation('com.google.guava:guava:32.0.1-android')
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = 'LotusOffSeasonV2'
rootProject.name = 'FrostAndFallout'


2 changes: 1 addition & 1 deletion src/main/java/dev/lotus/studio/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onDisable() {
if (databaseInitializer != null) {
databaseInitializer.closeConnection();
}
getLogger().info("LotusOffSeason plugin disabled!");
getLogger().info("Frost and Fallout plugin disabled!");
HandlerList.unregisterAll(this);
}
private void metric(){
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/dev/lotus/studio/event/ArmorEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import dev.lotus.studio.item.CustomItemManager;
import dev.lotus.studio.playerdata.PlayerManager;

import static org.bukkit.Bukkit.getLogger;

public class ArmorEvent implements Listener {
private final CustomItemManager customItemManager;

Expand All @@ -33,7 +35,7 @@ public void onArmorChanged(Player player) {

// Проверяем, зарегистрирован ли предмет в CustomItemManager
CustomItem customItem = customItemManager.getCustomItemByItemStack(armorPiece);
System.out.println("Найдено " + customItem);
getLogger().info("Найдено " + customItem);
if (customItem != null) {
temperatureResistance += customItem.getTemperatureResistance();
radiationResistance += customItem.getRadiationResistance();
Expand All @@ -43,7 +45,7 @@ public void onArmorChanged(Player player) {
// Устанавливаем сопротивление для игрока
PlayerManager.getInstance().getPlayerData(player).setTemperatureResistance(temperatureResistance);
PlayerManager.getInstance().getPlayerData(player).setRadiationResistance(radiationResistance);
System.out.println("Сопротивление температуре: " + temperatureResistance);
System.out.println("Сопротивление радиции: " + radiationResistance);
getLogger().info("Сопротивление температуре: " + temperatureResistance);
getLogger().info("Сопротивление радиции: " + radiationResistance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Component createProgressBar(double absoluteValue, String label, boolean s
progressBar = progressBar.append(Component.text("]"));

if (showValue) {
String numberValue = String.format("%2.1f", absoluteValue);
String numberValue = String.format(" %2.1f", absoluteValue);
progressBar = progressBar.append(Component.text(numberValue).color(TextColor.color(0xFFFFFF)));
}

Expand Down
345 changes: 131 additions & 214 deletions src/main/java/dev/lotus/studio/item/CustomItemManager.java

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/main/java/dev/lotus/studio/item/ItemKeys.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.lotus.studio.item;

import org.bukkit.NamespacedKey;

public class ItemKeys {
private ItemKeys() {}
public static final NamespacedKey FF_ID = new NamespacedKey("frostandfallout", "id");
public static final NamespacedKey ORAXEN_ID = new NamespacedKey("oraxen", "id");
}
3 changes: 3 additions & 0 deletions src/main/java/dev/lotus/studio/item/Provider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.lotus.studio.item;

public enum Provider { STANDARD, ORAXEN, NEXO }
6 changes: 4 additions & 2 deletions src/main/java/dev/lotus/studio/item/armor/CustomItem.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.lotus.studio.item.armor;

import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public interface CustomItem {
ItemStack getItemStack(); // Отримання предмета
double getTemperatureResistance(); // Отримання теплоємності
@NotNull String getCustomItem();
@NotNull ItemStack getItemStack();
double getTemperatureResistance();
double getRadiationResistance();
}
54 changes: 54 additions & 0 deletions src/main/java/dev/lotus/studio/item/armor/CustomItemFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dev.lotus.studio.item.armor;

import dev.lotus.studio.item.Provider;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.PluginManager;

import java.util.List;
import java.util.Locale;
import java.util.Objects;

public final class CustomItemFactory {
private final PluginManager pluginManager = Bukkit.getPluginManager();
private final boolean oraxenEnabled = pluginManager.isPluginEnabled("Oraxen");
private final boolean nexoEnabled = pluginManager.isPluginEnabled("Nexo");

public CustomItem fromSection(ConfigurationSection section) {
Objects.requireNonNull(section, "section");

String providerStr = section.getString("provider", section.getString("type", "standard"));
Provider provider = Provider.valueOf(providerStr.toUpperCase(Locale.ROOT));

String displayName = section.getString("displayName", null);
List<String> lore = section.getStringList("lore");
double tempRes = section.getDouble("temperatureResistance", 0.0);
double radRes = section.getDouble("radiationResistance", 0.0);

switch (provider) {
case STANDARD: {
String matName = section.getString("material");
if (matName == null) throw new IllegalArgumentException("Отсутствует material");
Material mat = Material.valueOf(matName.toUpperCase(Locale.ROOT));
return new StandardArmor(mat, displayName, lore, tempRes, radRes);
}
case ORAXEN: {
if (!oraxenEnabled) throw new IllegalStateException("Oraxen недоступен/не загружен");
String id = section.getString("oraxenId");
if (id == null || id.isEmpty())
throw new IllegalArgumentException("Отсутствует oraxenId");
return new OraxenCustomItem(id, tempRes, radRes, displayName, lore);
}
case NEXO: {
if (!nexoEnabled) throw new IllegalStateException("Nexo недоступен/не загружен");
String id = section.getString("nexoId");
if (id == null || id.isEmpty())
throw new IllegalArgumentException("Отсутствует nexoId");
return new NexoCustomItem(id, tempRes, radRes, displayName, lore);
}
default:
throw new IllegalArgumentException("Неизвестный provider: " + provider);
}
}
}
66 changes: 66 additions & 0 deletions src/main/java/dev/lotus/studio/item/armor/NexoCustomItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package dev.lotus.studio.item.armor;

import com.nexomc.nexo.api.NexoItems;
import com.nexomc.nexo.items.ItemBuilder;
import dev.lotus.studio.item.ItemKeys;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

public final class NexoCustomItem implements CustomItem {
private final String id;
private final double temperatureResistance;
private final double radiationResistance;
private final String displayName;
private final List<String> lore;

private ItemStack template;

public NexoCustomItem(@NotNull String nexoId,
double temperatureResistance,
double radiationResistance,
String displayName,
@NotNull List<String> lore) {
this.id = Objects.requireNonNull(nexoId, "nexoId");
this.temperatureResistance = temperatureResistance;
this.radiationResistance = radiationResistance;
this.displayName = displayName;
this.lore = List.copyOf(lore);
}

@Override public @NotNull String getCustomItem() { return id; }
@Override public double getTemperatureResistance() { return temperatureResistance; }
@Override public double getRadiationResistance() { return radiationResistance; }

@Override
public @NotNull ItemStack getItemStack() {
if (template == null) {
ItemBuilder builder = NexoItems.itemFromId(id);
if (builder == null) {
throw new IllegalArgumentException("Nexo item '" + id + "' не найден");
}
ItemStack itemStack = builder.build().clone();
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
if (displayName != null) meta.displayName(Component.text(displayName));
if (!lore.isEmpty()) {
List<TextComponent> components = lore.stream()
.map(Component::text)
.toList();
meta.lore(components);
}
meta.getPersistentDataContainer().set(ItemKeys.FF_ID, PersistentDataType.STRING, id);
itemStack.setItemMeta(meta);
}
template = itemStack;
}
return template.clone();
}
}
68 changes: 47 additions & 21 deletions src/main/java/dev/lotus/studio/item/armor/OraxenCustomItem.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,64 @@
package dev.lotus.studio.item.armor;

import dev.lotus.studio.item.ItemKeys;
import io.th0rgal.oraxen.api.OraxenItems;
import io.th0rgal.oraxen.items.ItemBuilder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

public class OraxenCustomItem implements CustomItem {
private final String oraxenId;
import java.util.List;
import java.util.Objects;

public final class OraxenCustomItem implements CustomItem {
private final String id;
private final double temperatureResistance;
private final double radiationResistance;
private final String displayName;
private final List<String> lore;

private ItemStack template;

public OraxenCustomItem(String oraxenId, double temperatureResistance, double radiationResistance) {
this.oraxenId = oraxenId;
public OraxenCustomItem(@NotNull String oraxenId,
double temperatureResistance,
double radiationResistance,
String displayName,
@NotNull List<String> lore) {
this.id = Objects.requireNonNull(oraxenId, "oraxenId");
this.temperatureResistance = temperatureResistance;
this.radiationResistance = radiationResistance;
this.displayName = displayName;
this.lore = List.copyOf(lore);
}

@Override
public ItemStack getItemStack() {
// Получение предмета через Oraxen API
ItemBuilder itemBuilder = OraxenItems.getItemById(oraxenId);
if (itemBuilder == null) {
throw new IllegalArgumentException("Oraxen предмет с ID '" + oraxenId + "' не найден.");
}
return itemBuilder.build();
}

@Override
public double getTemperatureResistance() {
return temperatureResistance;
}
@Override public @NotNull String getCustomItem() { return id; }
@Override public double getTemperatureResistance() { return temperatureResistance; }
@Override public double getRadiationResistance() { return radiationResistance; }

@Override
public double getRadiationResistance() {
return radiationResistance;
public @NotNull ItemStack getItemStack() {
if (template == null) {
ItemBuilder builder = OraxenItems.getItemById(id);
if (builder == null) throw new IllegalArgumentException("Oraxen предмет с ID '" + id + "' не найден");
ItemStack itemStack = builder.build();
ItemMeta meta = itemStack.getItemMeta();
if (meta != null) {
if (displayName != null) meta.displayName(Component.text(displayName));
if (!lore.isEmpty()) {
List<TextComponent> components = lore.stream()
.map(Component::text)
.toList();
meta.lore(components);
}
meta.getPersistentDataContainer().set(ItemKeys.FF_ID, PersistentDataType.STRING, id);
itemStack.setItemMeta(meta);
}
template = itemStack;
}
return template.clone();
}
}

69 changes: 45 additions & 24 deletions src/main/java/dev/lotus/studio/item/armor/StandardArmor.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,63 @@
package dev.lotus.studio.item.armor;

import dev.lotus.studio.item.ItemKeys;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

public class StandardArmor implements CustomItem{
private final ItemStack itemStack;
public final class StandardArmor implements CustomItem {
private final String id;
private final double temperatureResistance;
private final double radiationResistance;

public StandardArmor(Material material, String displayName, List<String> lore, double temperatureResistance, double radiationResistance) {
this.itemStack = new ItemStack(material);
private final Material material;
private final String displayName;
private final List<String> lore;

private ItemStack template;

public StandardArmor(@NotNull Material material,
String displayName,
@NotNull List<String> lore,
double temperatureResistance,
double radiationResistance) {
this.material = Objects.requireNonNull(material, "material");
this.displayName = displayName;
this.lore = List.copyOf(lore);
this.temperatureResistance = temperatureResistance;
this.radiationResistance = radiationResistance;

ItemMeta meta = this.itemStack.getItemMeta();
if (meta != null) {
meta.setDisplayName(displayName);
meta.setLore(lore);
this.itemStack.setItemMeta(meta);
}
}

@Override
public ItemStack getItemStack() {
return itemStack.clone();
this.id = material.name();
}

@Override
public double getTemperatureResistance() {
return temperatureResistance;
}
@Override public @NotNull String getCustomItem() { return id; }
@Override public double getTemperatureResistance() { return temperatureResistance; }
@Override public double getRadiationResistance() { return radiationResistance; }

@Override
public double getRadiationResistance() {
return radiationResistance;
public @NotNull ItemStack getItemStack() {
if (template == null) {
ItemStack is = new ItemStack(material);
ItemMeta meta = is.getItemMeta();
if (meta != null) {
if (displayName != null) meta.displayName(Component.text(displayName));
if (!lore.isEmpty()) {
List<TextComponent> components = lore.stream()
.map(Component::text)
.toList();
meta.lore(components);
}
meta.getPersistentDataContainer().set(ItemKeys.FF_ID, PersistentDataType.STRING, id);
is.setItemMeta(meta);
}
template = is;
}
return template.clone();
}

}
Loading