mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
Updated
This commit is contained in:
parent
eb05f43058
commit
c28c7064a8
@ -1,4 +1,4 @@
|
||||
package io.github.paldiu.simplexcore.banning;
|
||||
package io.github.paldiu.simplexcore.ban;
|
||||
|
||||
import io.github.paldiu.simplexcore.chat.Messages;
|
||||
import io.github.paldiu.simplexcore.config.Yaml;
|
||||
@ -16,11 +16,9 @@ import java.util.Date;
|
||||
/**
|
||||
* This class provides a way for you to handle your own banning.
|
||||
* Simply extend this class and create a new instance of the subclass.
|
||||
* Alternatively, you may use the
|
||||
*
|
||||
* @link BanFactory
|
||||
* Use this in synchrony with SimplexListener to process bans on player login/join.
|
||||
* Use this in synchrony with YamlFactory to create a new yaml file to store your bans, or to create an individual yaml file per user ban.
|
||||
* Alternatively, you may use {@link BanFactory#create} to create a new Ban instance.
|
||||
* Use this in synchrony with {@link io.github.paldiu.simplexcore.listener.SimplexListener} to process bans on player login/join.
|
||||
* Use this in synchrony with {@link io.github.paldiu.simplexcore.config.YamlFactory} to create a new yaml file to store your bans, or to create an individual yaml file per user ban.
|
||||
*/
|
||||
public abstract class Ban implements IBan {
|
||||
private final Player player;
|
||||
@ -58,7 +56,7 @@ public abstract class Ban implements IBan {
|
||||
File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans");
|
||||
|
||||
if (separateFiles) {
|
||||
Yaml yaml = new YamlFactory(Constants.getPlugin()).setPathways(null, fileLocation, player.getName() + ".yml");
|
||||
Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, player.getName() + ".yml");
|
||||
yaml.getConfig().createSection(getOffender().toString());
|
||||
ConfigurationSection section = yaml.getConfigurationSection(getOffender().toString());
|
||||
section.set("name", player.getName());
|
@ -1,4 +1,4 @@
|
||||
package io.github.paldiu.simplexcore.banning;
|
||||
package io.github.paldiu.simplexcore.ban;
|
||||
|
||||
import io.github.paldiu.simplexcore.chat.Messages;
|
||||
import io.github.paldiu.simplexcore.functional.Guard;
|
||||
@ -48,6 +48,10 @@ public final class BanFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of the abstract class Ban.
|
||||
* @return A new ban instance.
|
||||
*/
|
||||
public Ban create() {
|
||||
return new Ban(player, sender, type, banDuration) {
|
||||
@Override
|
@ -1,4 +1,4 @@
|
||||
package io.github.paldiu.simplexcore.banning;
|
||||
package io.github.paldiu.simplexcore.ban;
|
||||
|
||||
public enum BanType {
|
||||
PERMANENT("P-"),
|
@ -1,7 +1,6 @@
|
||||
package io.github.paldiu.simplexcore.banning;
|
||||
package io.github.paldiu.simplexcore.ban;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface IBan {
|
@ -15,7 +15,7 @@ public final class YamlFactory {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public Yaml setPathways(String resourcePath, File directory, String fileName) {
|
||||
public Yaml from(String resourcePath, File directory, String fileName) {
|
||||
this.resourcePath = resourcePath;
|
||||
this.directory = directory;
|
||||
this.fileName = fileName;
|
||||
@ -23,7 +23,7 @@ public final class YamlFactory {
|
||||
}
|
||||
|
||||
public Yaml setDefaultPathways() {
|
||||
return setPathways("config.yml", plugin.getDataFolder(), "config.yml");
|
||||
return from("config.yml", plugin.getDataFolder(), "config.yml");
|
||||
}
|
||||
|
||||
public Trio<String, File, String> pathways() {
|
||||
|
@ -0,0 +1,35 @@
|
||||
package io.github.paldiu.simplexcore.potion;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This interface is intended for creating custom potion effects.
|
||||
*/
|
||||
public interface IPotionEffect {
|
||||
@NotNull
|
||||
PotionEffect getEffect();
|
||||
|
||||
@NotNull
|
||||
PotionEffectType getType();
|
||||
|
||||
@NotNull
|
||||
String getName();
|
||||
|
||||
@NotNull
|
||||
Long getDuration();
|
||||
|
||||
@Nullable
|
||||
Particle getParticleType();
|
||||
|
||||
@Nullable
|
||||
Color getParticleColor();
|
||||
|
||||
@NotNull
|
||||
NamespacedKey getNamespacedKey();
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package io.github.paldiu.simplexcore.potion;
|
||||
|
||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class PotionsFactory {
|
||||
private PotionsFactory() {
|
||||
|
||||
}
|
||||
|
||||
public static void applyEffect(LivingEntity entity, PotionEffect... effect) {
|
||||
entity.addPotionEffects(Utilities.stream(effect).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
public static void applyEffect(LivingEntity entity, IPotionEffect... effect) {
|
||||
Utilities.forEach(effect, sim -> sim.getEffect().apply(entity)); // Interesting, not how it will be done in the end though.
|
||||
}
|
||||
}
|
@ -93,6 +93,5 @@ public final class Constants {
|
||||
return 622080000L;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,9 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import io.github.paldiu.simplexcore.banning.BanType;
|
||||
import io.github.paldiu.simplexcore.functional.Guard;
|
||||
import io.github.paldiu.simplexcore.functional.Validate;
|
||||
import io.github.paldiu.simplexcore.ban.BanType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class Utilities {
|
||||
@ -22,6 +18,10 @@ public final class Utilities {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> Stream<T> stream(T[] array) {
|
||||
return Arrays.stream(array);
|
||||
}
|
||||
|
||||
public static String generateBanId(BanType type) {
|
||||
final String charList = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
|
||||
final String numList = "0123456789";
|
||||
|
1
src/main/resources/config.yml
Normal file
1
src/main/resources/config.yml
Normal file
@ -0,0 +1 @@
|
||||
# Empty configuration file.
|
@ -1,7 +1,7 @@
|
||||
package io.github.paldiu.simplexcore.utils;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import io.github.paldiu.simplexcore.banning.BanType;
|
||||
import io.github.paldiu.simplexcore.ban.BanType;
|
||||
|
||||
public class UtilitiesTest extends TestCase {
|
||||
public void testGenerateBanId() {
|
||||
|
Loading…
Reference in New Issue
Block a user