Added plugin instance directly from config instead of adding it later

This commit is contained in:
Teriuihi 2023-09-22 01:46:14 +02:00
parent a385684eff
commit d453072465
6 changed files with 20 additions and 27 deletions

View File

@ -32,10 +32,12 @@ public class Config extends AbstractConfig {
static Config config;
private final Logger logger;
private final FishingEvent fishingEvent;
Config(FishingEvent fishingEvent, Logger logger) {
super(fishingEvent, "config.yml", logger);
this.logger = logger;
this.fishingEvent = fishingEvent;
}
public static void reload(FishingEvent fishingEvent, Logger logger) {
@ -121,6 +123,7 @@ public class Config extends AbstractConfig {
return;
}
npc = new UpgradeNPC(
config.fishingEvent,
config.logger,
npcCreateData,
upgrades.get()
@ -140,6 +143,7 @@ public class Config extends AbstractConfig {
return;
}
npc = new PrizeNPC(
config.fishingEvent,
config.logger,
npcCreateData,
prizes.get()

View File

@ -83,6 +83,8 @@ public class Fishes extends AbstractConfig {
}
FISH.add(new LavaFish(
config.fishingEvent,
config.logger,
(float) fishSection.getDouble("min-length", 0),
(float) fishSection.getDouble("max-length", 0),
fishSection.getString("fish-name", "default name"),

View File

@ -1,7 +1,9 @@
package com.alttd.fishingevent.fish;
import com.alttd.fishingevent.FishingEvent;
import com.alttd.fishingevent.objects.Rarity;
import com.alttd.fishingevent.util.Logger;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Particle;
@ -14,7 +16,8 @@ import java.util.Set;
public class LavaFish extends Fish {
public LavaFish(float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack, ArrayList<Set<Particle>> particles) {
public LavaFish(FishingEvent fishingEvent, Logger logger, float minLength, float maxLength, String fishName, Rarity rarity, ItemStack itemStack, ArrayList<Set<Particle>> particles) {
super(fishingEvent, logger);
}

View File

@ -23,12 +23,13 @@ public class PrizeNPC extends LibNPC implements NPC {
private final Logger logger;
private boolean isSpawned = false;
private final List<Prize> prizes;
private FishingEvent fishingEvent = null;
private final FishingEvent fishingEvent;
public PrizeNPC(Logger logger, NPCCreateData npcCreateData, List<Prize> prizes) {
public PrizeNPC(FishingEvent fishingEvent, Logger logger, NPCCreateData npcCreateData, List<Prize> prizes) {
this.npcCreateData = npcCreateData;
this.logger = logger;
this.prizes = prizes;
this.fishingEvent = fishingEvent;
}
@Override
@ -39,7 +40,6 @@ public class PrizeNPC extends LibNPC implements NPC {
@Override
public void spawnNPC(FishingEvent fishingEvent, Location location) {
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
this.fishingEvent = fishingEvent;
isSpawned = true;
}
@ -50,10 +50,6 @@ public class PrizeNPC extends LibNPC implements NPC {
@Override
public void rightClick(Player player) {
if (fishingEvent == null) {
player.sendMiniMessage(Messages.GUI.NOT_INITIALIZED, null);
return;
}
PrizesWindow prizesWindow = new PrizesWindow(player, logger, prizes);
new BukkitRunnable() {
@Override

View File

@ -3,10 +3,8 @@ package com.alttd.fishingevent.npc.types;
import com.alttd.fishingevent.FishingEvent;
import com.alttd.fishingevent.config.Messages;
import com.alttd.fishingevent.gui.windows.SellWindow;
import com.alttd.fishingevent.gui.windows.UpgradeWindow;
import com.alttd.fishingevent.npc.LibNPC;
import com.alttd.fishingevent.npc.NPC;
import com.alttd.fishingevent.objects.EnchantmentTrack;
import com.alttd.fishingevent.util.Logger;
import com.alttd.fishingevent.util.NPCCreateData;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@ -14,18 +12,17 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
public class SellNPC extends LibNPC implements NPC {
private final NPCCreateData npcCreateData;
private final Logger logger;
private boolean isSpawned = false;
private FishingEvent fishingEvent = null;
private final FishingEvent fishingEvent;
public SellNPC(Logger logger, NPCCreateData npcCreateData) {
this.npcCreateData = npcCreateData;
public SellNPC(FishingEvent fishingEvent, Logger logger, NPCCreateData npcCreateData) {
this.fishingEvent = fishingEvent;
this.logger = logger;
this.npcCreateData = npcCreateData;
}
@Override
@ -36,7 +33,6 @@ public class SellNPC extends LibNPC implements NPC {
@Override
public void spawnNPC(FishingEvent fishingEvent, Location location) {
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
this.fishingEvent = fishingEvent;
isSpawned = true;
}
@ -47,10 +43,6 @@ public class SellNPC extends LibNPC implements NPC {
@Override
public void rightClick(Player player) {
if (fishingEvent == null) {
player.sendMiniMessage(Messages.GUI.NOT_INITIALIZED, null);
return;
}
SellWindow sellWindow = new SellWindow(fishingEvent, player, logger);
if (!sellWindow.canOpen()) {
player.sendMiniMessage(Messages.GUI.NO_FISHING_ROD, null);

View File

@ -21,9 +21,10 @@ public class UpgradeNPC extends LibNPC implements NPC {
private final Logger logger;
private boolean isSpawned = false;
private final List<EnchantmentTrack> enchantmentTracks;
private FishingEvent fishingEvent = null;
private final FishingEvent fishingEvent;
public UpgradeNPC(Logger logger, NPCCreateData npcCreateData, List<EnchantmentTrack> enchantmentTracks) {
public UpgradeNPC(FishingEvent fishingEvent, Logger logger, NPCCreateData npcCreateData, List<EnchantmentTrack> enchantmentTracks) {
this.fishingEvent = fishingEvent;
this.npcCreateData = npcCreateData;
this.logger = logger;
this.enchantmentTracks = enchantmentTracks;
@ -37,7 +38,6 @@ public class UpgradeNPC extends LibNPC implements NPC {
@Override
public void spawnNPC(FishingEvent fishingEvent, Location location) {
defaultSpawnNPC(fishingEvent, location, npcCreateData, logger, this);
this.fishingEvent = fishingEvent;
isSpawned = true;
}
@ -48,10 +48,6 @@ public class UpgradeNPC extends LibNPC implements NPC {
@Override
public void rightClick(Player player) {
if (fishingEvent == null) {
player.sendMiniMessage(Messages.GUI.NOT_INITIALIZED, null);
return;
}
UpgradeWindow upgradeWindow = new UpgradeWindow(fishingEvent, player, logger, enchantmentTracks);
if (!upgradeWindow.canOpen()) {
player.sendMiniMessage(Messages.GUI.NO_FISHING_ROD, null);