forked from Upstream/mmocore
MMOCore managers are now marked final
This commit is contained in:
parent
9727f02051
commit
7d5f2fd9f2
@ -61,11 +61,10 @@ import java.util.logging.Level;
|
||||
public class MMOCore extends LuminePlugin {
|
||||
public static MMOCore plugin;
|
||||
|
||||
public ConfigManager configManager;
|
||||
public final WaypointManager waypointManager = new WaypointManager();
|
||||
public SoundManager soundManager;
|
||||
public RequestManager requestManager;
|
||||
public ConfigItemManager configItems;
|
||||
public final SoundManager soundManager = new SoundManager();
|
||||
public final RequestManager requestManager = new RequestManager();
|
||||
public final ConfigItemManager configItems = new ConfigItemManager();
|
||||
public final PlayerActionBar actionBarManager = new PlayerActionBar();
|
||||
public final SkillManager skillManager = new SkillManager();
|
||||
public final ClassManager classManager = new ClassManager();
|
||||
@ -82,6 +81,15 @@ public class MMOCore extends LuminePlugin {
|
||||
@Deprecated
|
||||
public final SkillTreeManager skillTreeManager = new SkillTreeManager();
|
||||
|
||||
// Profession managers
|
||||
public final CustomBlockManager mineManager = new CustomBlockManager();
|
||||
public final FishingManager fishingManager = new FishingManager();
|
||||
public final AlchemyManager alchemyManager = new AlchemyManager();
|
||||
public final EnchantManager enchantManager = new EnchantManager();
|
||||
public final SmithingManager smithingManager = new SmithingManager();
|
||||
|
||||
@NotNull
|
||||
public ConfigManager configManager;
|
||||
public VaultEconomy economy;
|
||||
public RegionHandler regionHandler = new DefaultRegionHandler();
|
||||
public PlaceholderParser placeholderParser = new DefaultParser();
|
||||
@ -91,13 +99,6 @@ public class MMOCore extends LuminePlugin {
|
||||
@NotNull
|
||||
public PartyModule partyModule;
|
||||
|
||||
// Profession managers
|
||||
public final CustomBlockManager mineManager = new CustomBlockManager();
|
||||
public final FishingManager fishingManager = new FishingManager();
|
||||
public final AlchemyManager alchemyManager = new AlchemyManager();
|
||||
public final EnchantManager enchantManager = new EnchantManager();
|
||||
public final SmithingManager smithingManager = new SmithingManager();
|
||||
|
||||
public boolean shouldDebugSQL = false;
|
||||
|
||||
private static final int MYTHICLIB_COMPATIBILITY_INDEX = 7;
|
||||
@ -408,10 +409,9 @@ public class MMOCore extends LuminePlugin {
|
||||
lootChests.initialize(clearBefore);
|
||||
restrictionManager.initialize(clearBefore);
|
||||
waypointManager.initialize(clearBefore);
|
||||
|
||||
requestManager = new RequestManager();
|
||||
soundManager = new SoundManager(new ConfigFile("sounds").getConfig());
|
||||
configItems = new ConfigItemManager(new ConfigFile("items").getConfig());
|
||||
requestManager.initialize(clearBefore);
|
||||
soundManager.initialize(clearBefore);
|
||||
configItems.initialize(clearBefore);
|
||||
|
||||
if (getConfig().isConfigurationSection("action-bar"))
|
||||
actionBarManager.reload(getConfig().getConfigurationSection("action-bar"));
|
||||
|
@ -1,31 +1,38 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.util.item.ConfigItem;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
public class ConfigItemManager implements MMOCoreManager {
|
||||
private final Map<String, ConfigItem> map = new HashMap<>();
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.util.item.ConfigItem;
|
||||
public void register(ConfigItem item) {
|
||||
map.put(item.getId(), item);
|
||||
}
|
||||
|
||||
public class ConfigItemManager {
|
||||
private final Map<String, ConfigItem> map = new HashMap<>();
|
||||
@Nullable
|
||||
public ConfigItem get(String id) {
|
||||
return map.get(id);
|
||||
}
|
||||
|
||||
public ConfigItemManager(FileConfiguration config) {
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
register(new ConfigItem(config.getConfigurationSection(key)));
|
||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load config item " + key);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
if (clearBefore)
|
||||
map.clear();
|
||||
|
||||
public void register(ConfigItem item) {
|
||||
map.put(item.getId(), item);
|
||||
}
|
||||
|
||||
public ConfigItem get(String id) {
|
||||
return map.get(id);
|
||||
}
|
||||
FileConfiguration config = new ConfigFile("items").getConfig();
|
||||
for (String key : config.getKeys(false))
|
||||
try {
|
||||
register(new ConfigItem(config.getConfigurationSection(key)));
|
||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load config item " + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.manager;
|
||||
|
||||
import net.Indyuce.mmocore.api.ConfigFile;
|
||||
import net.Indyuce.mmocore.api.SoundEvent;
|
||||
import net.Indyuce.mmocore.api.SoundObject;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
@ -9,16 +10,21 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SoundManager {
|
||||
public class SoundManager implements MMOCoreManager {
|
||||
private final Map<SoundEvent, SoundObject> sounds = new HashMap<>();
|
||||
|
||||
public SoundManager(FileConfiguration config) {
|
||||
for (SoundEvent sound : SoundEvent.values())
|
||||
sounds.put(sound, new SoundObject(config.getString(sound.name().replace("_", "-").toLowerCase())));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SoundObject getSound(SoundEvent event) {
|
||||
return Objects.requireNonNull(sounds.get(event), "Could not find sound for " + event.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
if (clearBefore)
|
||||
sounds.clear();
|
||||
|
||||
FileConfiguration config = new ConfigFile("sounds").getConfig();
|
||||
for (SoundEvent sound : SoundEvent.values())
|
||||
sounds.put(sound, new SoundObject(config.getString(sound.name().replace("_", "-").toLowerCase())));
|
||||
}
|
||||
}
|
||||
|
@ -2,35 +2,35 @@ package net.Indyuce.mmocore.manager.social;
|
||||
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.social.Request;
|
||||
import net.Indyuce.mmocore.manager.MMOCoreManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
public class RequestManager {
|
||||
public class RequestManager implements MMOCoreManager {
|
||||
private final Map<UUID, Request> requests = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Flushes friend requests every 5 minutes so there is no memory overleak
|
||||
*/
|
||||
public RequestManager() {
|
||||
Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5);
|
||||
}
|
||||
private boolean ENABLED;
|
||||
|
||||
@NotNull
|
||||
public Request getRequest(UUID uuid) {
|
||||
return requests.get(uuid);
|
||||
return Objects.requireNonNull(requests.get(uuid), "Could not find request with UUID '" + uuid.toString() + "'");
|
||||
}
|
||||
|
||||
public void registerRequest(Request request) {
|
||||
requests.put(request.getUniqueId(), request);
|
||||
}
|
||||
|
||||
public void unregisterRequest(UUID uuid) {
|
||||
requests.remove(uuid);
|
||||
@Nullable
|
||||
public Request unregisterRequest(UUID uuid) {
|
||||
return requests.remove(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes friend, guild or party invites every 5 minutes to prevent memory leaks
|
||||
*/
|
||||
private void flushRequests() {
|
||||
for (Iterator<Request> iterator = requests.values().iterator(); iterator.hasNext(); ) {
|
||||
Request next = iterator.next();
|
||||
@ -38,4 +38,18 @@ public class RequestManager {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The request map is NOT cleared, whatever state of the <code>clearBefore</code>
|
||||
* boolean as it's useless because they are guaranteed to disappear with time.
|
||||
*
|
||||
* @param clearBefore Useless here
|
||||
*/
|
||||
@Override
|
||||
public void initialize(boolean clearBefore) {
|
||||
if (!ENABLED) {
|
||||
Bukkit.getScheduler().runTaskTimer(MMOCore.plugin, this::flushRequests, 60 * 20, 60 * 20 * 5);
|
||||
ENABLED = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user