Merge branch 'Displayable-GUI-API' into videos-stupid-contributions

This commit is contained in:
Paldiu 2023-06-02 18:08:55 -05:00 committed by GitHub
commit 6edf320bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 276 additions and 260 deletions

View File

@ -52,12 +52,14 @@ public class CageCommand extends Commander
{
case "on" ->
{
((Datura) getPlugin()).getCager().cagePlayer(player.getUniqueId());
((Datura) getPlugin()).getCager()
.cagePlayer(player.getUniqueId());
sender.sendPlainMessage("Caged " + player.getName() + ".");
}
case "off" ->
{
((Datura) getPlugin()).getCager().uncagePlayer(player.getUniqueId());
((Datura) getPlugin()).getCager()
.uncagePlayer(player.getUniqueId());
sender.sendPlainMessage("Liberated " + player.getName() + ".");
}
}
@ -65,18 +67,21 @@ public class CageCommand extends Commander
@Completion(args = {"[material]"}, index = 2)
@Subcommand(permission = "datura.cage.custom", args = {Player.class, String.class, Material.class})
public void cagePlayer(final CommandSender sender, final Player player, final String string, final Material material)
public void cagePlayer(final CommandSender sender, final Player player, final String string,
final Material material)
{
switch (string.toLowerCase())
{
case "on" ->
{
((Datura) getPlugin()).getCager().cagePlayer(player.getUniqueId(), material);
((Datura) getPlugin()).getCager()
.cagePlayer(player.getUniqueId(), material);
sender.sendPlainMessage("Caged " + player.getName() + ".");
}
case "off" ->
{
((Datura) getPlugin()).getCager().uncagePlayer(player.getUniqueId());
((Datura) getPlugin()).getCager()
.uncagePlayer(player.getUniqueId());
sender.sendPlainMessage("Liberated " + player.getName() + ".");
}
}

View File

@ -31,8 +31,7 @@ public final class LockerCommand extends Commander
.lock(player);
sender.sendPlainMessage("Locked " + player.getName() + ".");
}
else if (string.equalsIgnoreCase("off"))
} else if (string.equalsIgnoreCase("off"))
{
((Datura) getPlugin()).getLocker()
.unlock(player);

View File

@ -26,9 +26,7 @@ public class SimpleUserData implements UserData
private final UserDataUpdateEvent event = new UserDataUpdateEvent(this);
private Group group;
private long playtime;
private boolean frozen;
private boolean canInteract;
private boolean caged;
private AtomicLong balance;
private boolean transactionsFrozen;
@ -49,7 +47,6 @@ public class SimpleUserData implements UserData
final User user,
final Group group,
final long playtime,
final boolean frozen,
final boolean canInteract,
final long balance,
final boolean transactionsFrozen)
@ -59,7 +56,6 @@ public class SimpleUserData implements UserData
this.user = user;
this.group = group;
this.playtime = playtime;
this.frozen = frozen;
this.canInteract = canInteract;
this.balance = new AtomicLong(balance);
this.transactionsFrozen = transactionsFrozen;
@ -82,8 +78,7 @@ public class SimpleUserData implements UserData
final Player player = Bukkit.getPlayer(u);
if (player == null)
throw new IllegalStateException(
"Player should be online but they are not!");
throw new IllegalStateException("Player should be online but they are not!");
final User user = new FreedomUser(player);
final Group group = CommonsBase.getInstance()
@ -92,13 +87,11 @@ public class SimpleUserData implements UserData
.getGroup(g);
final long playtime = result.getLong("playtime");
final boolean frozen = result.getBoolean("frozen");
final boolean canInteract = result.getBoolean("canInteract");
final boolean caged = result.getBoolean("caged");
final long balance = result.getLong("balance");
final boolean transactionsFrozen = result.getBoolean(
"transactionsFrozen");
return new SimpleUserData(u, username, user, group, playtime, frozen,
final boolean transactionsFrozen = result.getBoolean("transactionsFrozen");
return new SimpleUserData(u, username, user, group, playtime,
canInteract, balance, transactionsFrozen);
}
}
@ -118,8 +111,8 @@ public class SimpleUserData implements UserData
}
final Player player = Bukkit.getPlayer(UUID.fromString(uuid));
if (player == null) throw new IllegalStateException(
"Player should be online but they are not!");
if (player == null) throw new IllegalStateException("Player should be online but they are not!");
return new SimpleUserData(player);
}, CommonsBase.getInstance()
.getExecutor()
@ -185,19 +178,6 @@ public class SimpleUserData implements UserData
this.playtime = 0L;
}
@Override
public boolean isFrozen()
{
return frozen;
}
@Override
public void setFrozen(final boolean frozen)
{
event.ping();
this.frozen = true;
}
@Override
public boolean canInteract()
{

View File

@ -46,13 +46,17 @@ public class CakeCommand extends Commander
@Base
public void broadcastCake(final CommandSender sender)
{
Bukkit.broadcast(FreedomMiniMessage.deserialize(true, "<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of cake.</rainbow>"));
Bukkit.broadcast(FreedomMiniMessage.deserialize(true,
"<rainbow>But there's no sense crying over every mistake. You just keep on trying till you run out of " +
"cake.</rainbow>"));
final ItemStack stack = new ItemStack(Material.CAKE, 1);
final ItemMeta meta = stack.getItemMeta();
meta.displayName(FreedomMiniMessage.deserialize(true, "<dark_gray>The <white>Lie"));
stack.setItemMeta(meta);
Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().addItem(stack));
Bukkit.getOnlinePlayers()
.forEach(player -> player.getInventory()
.addItem(stack));
}
}

View File

@ -20,8 +20,10 @@ public final class ClownfishItem extends ShopItem
{
if (target == null) return;
final Location location = user.getEyeLocation().clone();
final Vector vector = location.getDirection().multiply(2);
final Location location = user.getEyeLocation()
.clone();
final Vector vector = location.getDirection()
.multiply(2);
target.setVelocity(vector);
}

View File

@ -27,6 +27,7 @@ public final class BasicTrail extends SimpleTrail
final Location location = player.getLocation()
.clone()
.subtract(0, 1, 0);
location.getWorld().spawnParticle(particle, location, 1, 0.0, 0.5, 0.0, options);
location.getWorld()
.spawnParticle(particle, location, 1, 0.0, 0.5, 0.0, options);
}
}

View File

@ -20,6 +20,7 @@ public final class HeartTrail extends SimpleTrail
final Location location = player.getLocation()
.clone()
.subtract(0, 1, 0);
location.getWorld().spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0);
location.getWorld()
.spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0);
}
}

View File

@ -21,7 +21,8 @@ public abstract class SimpleTrail implements Trail
private Set<Color> gradientColor = null;
private boolean active = false;
protected SimpleTrail(final Player player, final TrailType trailType) {
protected SimpleTrail(final Player player, final TrailType trailType)
{
this.associatedPlayerUUID = player.getUniqueId();
this.trailType = trailType;
}

View File

@ -25,6 +25,7 @@ public final class StrobeTrail extends SimpleTrail
final Location location = player.getLocation()
.clone()
.subtract(0, 1, 0);
location.getWorld().spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0, dustTransition);
location.getWorld()
.spawnParticle(getTrailType().getType(), location, 1, 0.0, 0.5, 0.0, dustTransition);
}
}

View File

@ -4,7 +4,8 @@ import org.bukkit.entity.Player;
public final class TrailProvider
{
public BasicTrail basicTrail(final Player player) {
public BasicTrail basicTrail(final Player player)
{
return new BasicTrail(player);
}

View File

@ -20,7 +20,8 @@ public class CommonsBase extends JavaPlugin
@Override
public void onDisable()
{
Bukkit.getScheduler().runTaskLater(this, () -> getRegistrations()
Bukkit.getScheduler()
.runTaskLater(this, () -> getRegistrations()
.getServiceRegistry()
.stopAllServices(), 1L);

View File

@ -1,15 +1,11 @@
package me.totalfreedom.config;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.List;
public interface Configuration
{
YamlConfiguration asYaml();
void save() throws IOException;
void load() throws IOException;

View File

@ -0,0 +1,6 @@
package me.totalfreedom.config;
public final class YamlWrapper
{
}

View File

@ -30,7 +30,9 @@ public final class Displayable implements Inventory, InventoryHolder
// If the size is not a multiple of nine, find the difference to the next highest multiple of 9 and make up
// the difference.
this.size = (size % 9 == 0) ? size : size + (9 - size % 9);
this.size = (size % 9 == 0)
? size
: size + (9 - size % 9);
this.contents = new ItemStack[size];
}

View File

@ -3,10 +3,8 @@ package me.totalfreedom.particle;
import me.totalfreedom.api.Interpolator;
import me.totalfreedom.utils.InterpolationUtils;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.Particle;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -3,6 +3,7 @@ package me.totalfreedom.provider;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -21,6 +22,7 @@ public class ContextProvider
toInt(string),
toLong(string),
toFloat(string),
toMaterial(string),
toPlayer(string),
toWorld(string),
toLocation(string),
@ -92,6 +94,11 @@ public class ContextProvider
}
}
private @Nullable Material toMaterial(final String string)
{
return Material.matchMaterial(string);
}
private @Nullable Player toPlayer(final String string)
{
return Bukkit.getPlayer(string);

View File

@ -3,6 +3,7 @@ package me.totalfreedom.service;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.Executor;
@ -15,7 +16,7 @@ public final class ServiceSubscription<T extends Service>
private boolean isActive = false;
ServiceSubscription(final JavaPlugin plugin, final T service, final boolean async)
ServiceSubscription(@NotNull final JavaPlugin plugin, @NotNull final T service, final boolean async)
{
this.service = service;
this.async = async;
@ -52,12 +53,8 @@ public final class ServiceSubscription<T extends Service>
public void stop()
{
this.isActive = false;
Bukkit.getScheduler().cancelTask(this.getServiceId());
}
public T getService()
{
return service;
Bukkit.getScheduler()
.cancelTask(this.getServiceId());
}
public int getServiceId()
@ -65,6 +62,12 @@ public final class ServiceSubscription<T extends Service>
return serviceId;
}
@NotNull
public T getService()
{
return service;
}
public boolean isAsync()
{
return async;

View File

@ -56,14 +56,6 @@ public class FreedomLogger implements Audience
public String infoComponent(final Supplier<Component> component)
{
return this.infoComponent(component.get());
} /**
* This method allows you to log a message to the console.
*
* @param message The message to send.
*/
public void info(final String message)
{
logger.info(message);
}
/**
@ -78,6 +70,14 @@ public class FreedomLogger implements Audience
logger.info(plainText);
return plainText;
} /**
* This method allows you to log a message to the console.
*
* @param message The message to send.
*/
public void info(final String message)
{
logger.info(message);
}
/**

View File

@ -32,14 +32,9 @@ import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
*/
public class FreedomMiniMessage
{
private FreedomMiniMessage()
{
throw new UnsupportedOperationException("Instantiation of a static utility class is not supported.");
}
private static final MiniMessage unsafe = MiniMessage.miniMessage();
private static final MiniMessage safe = MiniMessage.builder().tags(TagResolver.resolver(
private static final MiniMessage safe = MiniMessage.builder()
.tags(TagResolver.resolver(
StandardTags.color(),
StandardTags.rainbow(),
StandardTags.gradient(),
@ -48,11 +43,19 @@ public class FreedomMiniMessage
StandardTags.decorations(TextDecoration.BOLD),
StandardTags.decorations(TextDecoration.STRIKETHROUGH),
StandardTags.decorations(TextDecoration.UNDERLINED)
)).build();
))
.build();
private FreedomMiniMessage()
{
throw new UnsupportedOperationException("Instantiation of a static utility class is not supported.");
}
/**
* Deserializes an input string using an instance of MiniMessage that is either safe (resolves only a specific set of tags)
* Deserializes an input string using an instance of MiniMessage that is either safe (resolves only a specific
* set of tags)
* or unsafe (resolves all tags).
*
* @param safe Whether to use a safe instance of MiniMessage
* @param input An input string formatted with MiniMessage's input
* @param placeholders Custom placeholders to use when processing the input
@ -60,18 +63,23 @@ public class FreedomMiniMessage
*/
public static Component deserialize(boolean safe, String input, TagResolver... placeholders)
{
return (safe ? FreedomMiniMessage.safe : unsafe).deserialize(input, placeholders);
return (safe
? FreedomMiniMessage.safe
: unsafe).deserialize(input, placeholders);
}
/**
* Serializes an input component using an instance of MiniMessage that is either safe (resolves only a specific set
* of tags) or unsafe (resolves all tags).
*
* @param safe Whether to use a safe instance of MiniMessage
* @param input An already processed component
* @return A processed Component
*/
public static String serialize(boolean safe, Component input)
{
return (safe ? FreedomMiniMessage.safe : unsafe).serialize(input);
return (safe
? FreedomMiniMessage.safe
: unsafe).serialize(input);
}
}