Creating some DI

This commit is contained in:
Paldiu 2021-03-26 13:28:03 -05:00
parent 81dbe3b234
commit c3c9b965e5
10 changed files with 120 additions and 21 deletions

View File

@ -43,7 +43,7 @@ public final class SimplexCorePlugin extends SimplexModule<SimplexCorePlugin> {
getInternals().reload(); getInternals().reload();
// //
SimplexListener.register(new DependencyListener(), this); SimplexListener.register(new DependencyListener(), this);
new Announcer(); new Announcer(this);
} catch (Exception ex) { } catch (Exception ex) {
suspended = true; suspended = true;
// TODO: Write an output to a file with why it suspended. // TODO: Write an output to a file with why it suspended.

View File

@ -11,8 +11,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicReference;
import static io.github.simplexdev.simplexcore.utils.Utilities.pathway; import static io.github.simplexdev.simplexcore.utils.Utilities.pathway;
@ -124,12 +126,18 @@ public final class BanFactory {
return null; return null;
} }
private VoidSupplier assignBanDuration() { private VoidSupplier assignBanDuration(Long... time) {
return () -> { return () -> {
if (type.equals(BanType.PERMANENT)) { if (type.equals(BanType.PERMANENT)) {
banDuration = TickedTime.YEAR * 99; banDuration = TickedTime.YEAR * 99;
} else if (type.equals(BanType.TEMPORARY)) { } else if (type.equals(BanType.TEMPORARY)) {
banDuration = TickedTime.DAY; banDuration = TickedTime.DAY;
} else if (type.equals(BanType.CUSTOM)) {
long tmp = 0L;
for (long t : time) {
tmp += t;
}
banDuration = tmp;
} else { } else {
banDuration = TickedTime.MINUTE * 5; banDuration = TickedTime.MINUTE * 5;
} }

View File

@ -2,7 +2,8 @@ package io.github.simplexdev.simplexcore.ban;
public enum BanType { public enum BanType {
PERMANENT("P-"), PERMANENT("P-"),
TEMPORARY("T-"); TEMPORARY("T-"),
CUSTOM("C-");
private final String prefix; private final String prefix;

View File

@ -8,7 +8,7 @@ import net.minecraft.server.v1_16_R3.Enchantment;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
public abstract class SimplexEnch extends Enchantment implements IEnchant { 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) { protected SimplexEnch(SimplexModule<?> plugin, Rarity rarity, EnchantmentSlotType type, EnumItemSlot[] enumSlot) {
super(rarity, type, enumSlot); super(rarity, type, enumSlot);

View File

@ -1,5 +1,6 @@
package io.github.simplexdev.simplexcore.module; package io.github.simplexdev.simplexcore.module;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.command.CommandLoader; import io.github.simplexdev.simplexcore.command.CommandLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -63,11 +64,15 @@ public abstract class SimplexModule<T extends SimplexModule<T>> extends JavaPlug
return this.getDataFolder(); return this.getDataFolder();
} }
public synchronized ModuleRegistry getRegistry() { public ModuleRegistry getRegistry() {
return ModuleRegistry.getInstance(); return ModuleRegistry.getInstance();
} }
public synchronized CommandLoader getCommandLoader() { public CommandLoader getCommandLoader() {
return CommandLoader.getInstance(); return CommandLoader.getInstance();
} }
public SimplexCorePlugin getProvider() {
return SimplexCorePlugin.getInstance();
}
} }

View File

@ -1,18 +1,21 @@
package io.github.simplexdev.simplexcore.particle; package io.github.simplexdev.simplexcore.particle;
import io.github.simplexdev.api.IParticleEffect; import io.github.simplexdev.api.IParticleEffect;
import io.github.simplexdev.simplexcore.module.SimplexModule;
import org.bukkit.*; import org.bukkit.*;
import java.util.*; import java.util.*;
public class ParticleFactory { public final class ParticleFactory {
private final SimplexModule<?> plugin;
private float size = 2F; private float size = 2F;
private long duration = 20L * 15L; private long duration = 20L * 15L;
private final Set<Particle> particleSet = new HashSet<>(); private final Set<Particle> particleSet = new HashSet<>();
private final Map<Particle, Color> particleColorMap = new HashMap<>(); private final Map<Particle, Color> particleColorMap = new HashMap<>();
private final Set<Effect> particleEffects = new HashSet<>(); private final Set<Effect> particleEffects = new HashSet<>();
public ParticleFactory() { public ParticleFactory(SimplexModule<?> plugin) {
this.plugin = plugin;
} }
public ParticleFactory setSize(float size) { public ParticleFactory setSize(float size) {
@ -90,4 +93,8 @@ public class ParticleFactory {
world.spawnParticle(particle, location, 20); world.spawnParticle(particle, location, 20);
}); });
} }
public final SimplexModule<?> getPlugin() {
return plugin;
}
} }

View File

@ -9,7 +9,7 @@ import java.util.stream.Collectors;
public final class PotionsFactory { public final class PotionsFactory {
private PotionsFactory() { private PotionsFactory() {
throw new AssertionError("This class should not be instantiated!");
} }
public static void applyEffect(LivingEntity entity, PotionEffect... effect) { public static void applyEffect(LivingEntity entity, PotionEffect... effect) {

View File

@ -1,5 +1,80 @@
package io.github.simplexdev.simplexcore.structures; 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 // TODO: Write this
} }

View File

@ -2,6 +2,7 @@ package io.github.simplexdev.simplexcore.task;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.chat.Messages; import io.github.simplexdev.simplexcore.chat.Messages;
import io.github.simplexdev.simplexcore.module.SimplexModule;
import io.github.simplexdev.simplexcore.utils.TickedTime; import io.github.simplexdev.simplexcore.utils.TickedTime;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -11,16 +12,15 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Announcer extends SimplexTask { public class Announcer extends SimplexTask {
private final List<String> stringList = new ArrayList<>() {{ private final List<String> stringList = new ArrayList<>() {{
add("Join our discord!" + Messages.DISCORD.getMessage()); add("Join our discord!" + Messages.DISCORD.getMessage());
add("Thank you for using SimplexCore!"); add("Thank you for using SimplexCore!");
add("https://github.com/SimplexDevelopment/SimplexCore"); add("https://github.com/SimplexDevelopment/SimplexCore");
}}; }};
public Announcer() { public Announcer(SimplexCorePlugin plugin) {
super(TickedTime.HOUR); super(plugin, TickedTime.HOUR);
register(this, SimplexCorePlugin.getInstance(), true, false); register(this, true, false);
} }
@Override @Override

View File

@ -15,6 +15,7 @@ import java.util.function.Consumer;
public abstract class SimplexTask implements Consumer<BukkitTask> { public abstract class SimplexTask implements Consumer<BukkitTask> {
protected final long DELAY; protected final long DELAY;
protected final long INTERVAL; protected final long INTERVAL;
protected final SimplexModule<?> plugin;
protected Date lastRan = new Date(); protected Date lastRan = new Date();
protected Timer timer = new Timer(); protected Timer timer = new Timer();
protected int taskId; 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 initialDelay How long before the first time the task executes.
* @param interval How long before the task repeats itself. * @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; DELAY = initialDelay;
INTERVAL = interval; 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. * @param interval How often the task should repeat. Every 20L is 1 second.
* You should use {@link TickedTime} for determining the related server timings. * You should use {@link TickedTime} for determining the related server timings.
*/ */
protected SimplexTask(long interval) { protected SimplexTask(SimplexModule<?> plugin, long interval) {
DELAY = 0L; DELAY = 0L;
INTERVAL = interval; INTERVAL = interval;
this.plugin = plugin;
} }
/** /**
* Constructor which automatically registers the DELAY as 30 seconds * Constructor which automatically registers the DELAY as 30 seconds
* and the INTERVAL at which it executes as 5 minutes. * 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. 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. 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}. * {@link org.bukkit.scheduler.BukkitScheduler}.
* *
* @param task The instance of a subclass of this class. * @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 repeating Whether or not the task should repeat.
* @param delayed Whether or not to delay the first time the task runs. * @param delayed Whether or not to delay the first time the task runs.
* @param <T> A subclass of SimplexTask. * @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) { if (delayed && repeating) {
SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL);
} else if (delayed) { } else if (delayed) {
@ -85,7 +88,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
* @param <T> A subclass of SimplexTask. * @param <T> A subclass of SimplexTask.
*/ */
public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin, boolean delayed) { 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. * @param <T> A subclass of SimplexTask.
*/ */
public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin) { public <T extends SimplexTask> void register(T task, SimplexModule<?> plugin) {
register(task, plugin, false, false); register(task, false, false);
} }
/** /**