mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2025-01-09 07:57:38 +00:00
Creating some DI
This commit is contained in:
parent
81dbe3b234
commit
c3c9b965e5
src/main/java/io/github/simplexdev/simplexcore
@ -43,7 +43,7 @@ public final class SimplexCorePlugin extends SimplexModule<SimplexCorePlugin> {
|
||||
getInternals().reload();
|
||||
//
|
||||
SimplexListener.register(new DependencyListener(), this);
|
||||
new Announcer();
|
||||
new Announcer(this);
|
||||
} catch (Exception ex) {
|
||||
suspended = true;
|
||||
// TODO: Write an output to a file with why it suspended.
|
||||
|
@ -11,8 +11,10 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static io.github.simplexdev.simplexcore.utils.Utilities.pathway;
|
||||
|
||||
@ -124,12 +126,18 @@ public final class BanFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
private VoidSupplier assignBanDuration() {
|
||||
private VoidSupplier assignBanDuration(Long... time) {
|
||||
return () -> {
|
||||
if (type.equals(BanType.PERMANENT)) {
|
||||
banDuration = TickedTime.YEAR * 99;
|
||||
} else if (type.equals(BanType.TEMPORARY)) {
|
||||
banDuration = TickedTime.DAY;
|
||||
} else if (type.equals(BanType.CUSTOM)) {
|
||||
long tmp = 0L;
|
||||
for (long t : time) {
|
||||
tmp += t;
|
||||
}
|
||||
banDuration = tmp;
|
||||
} else {
|
||||
banDuration = TickedTime.MINUTE * 5;
|
||||
}
|
||||
|
@ -2,7 +2,8 @@ package io.github.simplexdev.simplexcore.ban;
|
||||
|
||||
public enum BanType {
|
||||
PERMANENT("P-"),
|
||||
TEMPORARY("T-");
|
||||
TEMPORARY("T-"),
|
||||
CUSTOM("C-");
|
||||
|
||||
private final String prefix;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import net.minecraft.server.v1_16_R3.Enchantment;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
public abstract class SimplexEnch extends Enchantment implements IEnchant {
|
||||
protected final SimplexModule<?> plugin; // What was your question?
|
||||
protected final SimplexModule<?> plugin;
|
||||
|
||||
protected SimplexEnch(SimplexModule<?> plugin, Rarity rarity, EnchantmentSlotType type, EnumItemSlot[] enumSlot) {
|
||||
super(rarity, type, enumSlot);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.github.simplexdev.simplexcore.module;
|
||||
|
||||
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
|
||||
import io.github.simplexdev.simplexcore.command.CommandLoader;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -63,11 +64,15 @@ public abstract class SimplexModule<T extends SimplexModule<T>> extends JavaPlug
|
||||
return this.getDataFolder();
|
||||
}
|
||||
|
||||
public synchronized ModuleRegistry getRegistry() {
|
||||
public ModuleRegistry getRegistry() {
|
||||
return ModuleRegistry.getInstance();
|
||||
}
|
||||
|
||||
public synchronized CommandLoader getCommandLoader() {
|
||||
public CommandLoader getCommandLoader() {
|
||||
return CommandLoader.getInstance();
|
||||
}
|
||||
|
||||
public SimplexCorePlugin getProvider() {
|
||||
return SimplexCorePlugin.getInstance();
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
package io.github.simplexdev.simplexcore.particle;
|
||||
|
||||
import io.github.simplexdev.api.IParticleEffect;
|
||||
import io.github.simplexdev.simplexcore.module.SimplexModule;
|
||||
import org.bukkit.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ParticleFactory {
|
||||
public final class ParticleFactory {
|
||||
private final SimplexModule<?> plugin;
|
||||
private float size = 2F;
|
||||
private long duration = 20L * 15L;
|
||||
private final Set<Particle> particleSet = new HashSet<>();
|
||||
private final Map<Particle, Color> particleColorMap = new HashMap<>();
|
||||
private final Set<Effect> particleEffects = new HashSet<>();
|
||||
|
||||
public ParticleFactory() {
|
||||
public ParticleFactory(SimplexModule<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public ParticleFactory setSize(float size) {
|
||||
@ -90,4 +93,8 @@ public class ParticleFactory {
|
||||
world.spawnParticle(particle, location, 20);
|
||||
});
|
||||
}
|
||||
|
||||
public final SimplexModule<?> getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public final class PotionsFactory {
|
||||
private PotionsFactory() {
|
||||
|
||||
throw new AssertionError("This class should not be instantiated!");
|
||||
}
|
||||
|
||||
public static void applyEffect(LivingEntity entity, PotionEffect... effect) {
|
||||
|
@ -1,5 +1,80 @@
|
||||
package io.github.simplexdev.simplexcore.structures;
|
||||
|
||||
public class Structure {
|
||||
import io.github.simplexdev.api.IStructure;
|
||||
import io.github.simplexdev.simplexcore.math.Size;
|
||||
import io.github.simplexdev.simplexcore.module.SimplexModule;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class Structure implements IStructure {
|
||||
private final SimplexModule<?> plugin;
|
||||
|
||||
public Structure(SimplexModule<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespacedKey getNamespacedKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateNaturally() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Location location, World world) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Location location, World world, boolean generateNaturally) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Size getApproximateSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Block[] getBlocks() {
|
||||
return new Block[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Block, Location> getBlockLocations() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getStructureFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SimplexModule<?> getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
// TODO: Write this
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.simplexdev.simplexcore.task;
|
||||
|
||||
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
|
||||
import io.github.simplexdev.simplexcore.chat.Messages;
|
||||
import io.github.simplexdev.simplexcore.module.SimplexModule;
|
||||
import io.github.simplexdev.simplexcore.utils.TickedTime;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -11,16 +12,15 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Announcer extends SimplexTask {
|
||||
|
||||
private final List<String> stringList = new ArrayList<>() {{
|
||||
add("Join our discord!" + Messages.DISCORD.getMessage());
|
||||
add("Thank you for using SimplexCore!");
|
||||
add("https://github.com/SimplexDevelopment/SimplexCore");
|
||||
}};
|
||||
|
||||
public Announcer() {
|
||||
super(TickedTime.HOUR);
|
||||
register(this, SimplexCorePlugin.getInstance(), true, false);
|
||||
public Announcer(SimplexCorePlugin plugin) {
|
||||
super(plugin, TickedTime.HOUR);
|
||||
register(this, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -15,6 +15,7 @@ import java.util.function.Consumer;
|
||||
public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
protected final long DELAY;
|
||||
protected final long INTERVAL;
|
||||
protected final SimplexModule<?> plugin;
|
||||
protected Date lastRan = new Date();
|
||||
protected Timer timer = new Timer();
|
||||
protected int taskId;
|
||||
@ -25,9 +26,10 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
* @param initialDelay How long before the first time the task executes.
|
||||
* @param interval How long before the task repeats itself.
|
||||
*/
|
||||
protected SimplexTask(long initialDelay, long interval) {
|
||||
protected SimplexTask(SimplexModule<?> plugin, long initialDelay, long interval) {
|
||||
DELAY = initialDelay;
|
||||
INTERVAL = interval;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,16 +39,18 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
* @param interval How often the task should repeat. Every 20L is 1 second.
|
||||
* You should use {@link TickedTime} for determining the related server timings.
|
||||
*/
|
||||
protected SimplexTask(long interval) {
|
||||
protected SimplexTask(SimplexModule<?> plugin, long interval) {
|
||||
DELAY = 0L;
|
||||
INTERVAL = interval;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor which automatically registers the DELAY as 30 seconds
|
||||
* and the INTERVAL at which it executes as 5 minutes.
|
||||
*/
|
||||
protected SimplexTask() {
|
||||
protected SimplexTask(SimplexModule<?> plugin) {
|
||||
this.plugin = plugin;
|
||||
DELAY = TickedTime.SECOND * 30; // 30 seconds until the task triggers for the first time.
|
||||
INTERVAL = TickedTime.MINUTE * 5; // Task will run at 5 minute intervals once the first trigger has been called.
|
||||
}
|
||||
@ -56,12 +60,11 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
* {@link org.bukkit.scheduler.BukkitScheduler}.
|
||||
*
|
||||
* @param task The instance of a subclass of this class.
|
||||
* @param plugin Your plugin instance.
|
||||
* @param repeating Whether or not the task should repeat.
|
||||
* @param delayed Whether or not to delay the first time the task runs.
|
||||
* @param <T> A subclass of SimplexTask.
|
||||
*/
|
||||
public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin, boolean repeating, boolean delayed) {
|
||||
public <T extends SimplexTask> void register(T task, boolean repeating, boolean delayed) {
|
||||
if (delayed && repeating) {
|
||||
SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL);
|
||||
} else if (delayed) {
|
||||
@ -85,7 +88,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
* @param <T> A subclass of SimplexTask.
|
||||
*/
|
||||
public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin, boolean delayed) {
|
||||
register(task, plugin, false, delayed);
|
||||
register(task, false, delayed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,7 +101,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
|
||||
* @param <T> A subclass of SimplexTask.
|
||||
*/
|
||||
public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin) {
|
||||
register(task, plugin, false, false);
|
||||
register(task, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user