mirror of
https://github.com/SimplexDevelopment/FreedomNetworkSuite.git
synced 2024-11-14 05:03:33 +00:00
Implemented Fuckoff command from TFM back (#16)
* Implemented Fuckoff command back from TFM * Actual use the radius field * Change default radius to 15 * Renamed Fuckoff#pushPlayers * Use command API properly
This commit is contained in:
parent
dd4e1bbda0
commit
e1a6b5e587
@ -1,6 +1,7 @@
|
||||
package me.totalfreedom.datura;
|
||||
|
||||
import me.totalfreedom.base.Patchwork;
|
||||
import me.totalfreedom.datura.features.Fuckoff;
|
||||
import me.totalfreedom.datura.features.CommandSpy;
|
||||
import me.totalfreedom.datura.punishment.Cager;
|
||||
import me.totalfreedom.datura.punishment.Halter;
|
||||
@ -21,6 +22,7 @@ public class Datura extends JavaPlugin
|
||||
|
||||
// Features
|
||||
private final CommandSpy commandSpy = new CommandSpy();
|
||||
private final Fuckoff fuckoff = new Fuckoff();
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
@ -38,6 +40,10 @@ public class Datura extends JavaPlugin
|
||||
.getRegistrations()
|
||||
.getServiceTaskRegistry()
|
||||
.registerService(SubscriptionProvider.syncService(this, cager));
|
||||
Patchwork.getInstance()
|
||||
.getRegistrations()
|
||||
.getServiceTaskRegistry()
|
||||
.registerService(SubscriptionProvider.syncService(this, fuckoff));
|
||||
|
||||
Bukkit.getPluginManager()
|
||||
.registerEvents(halter, this);
|
||||
@ -65,7 +71,13 @@ public class Datura extends JavaPlugin
|
||||
return cager;
|
||||
}
|
||||
|
||||
public CommandSpy getCommandSpy() {
|
||||
public CommandSpy getCommandSpy()
|
||||
{
|
||||
return commandSpy;
|
||||
}
|
||||
|
||||
public Fuckoff getFuckoff()
|
||||
{
|
||||
return fuckoff;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,62 @@
|
||||
package me.totalfreedom.datura.cmd;
|
||||
|
||||
import me.totalfreedom.base.Shortcuts;
|
||||
import me.totalfreedom.command.Commander;
|
||||
import me.totalfreedom.command.annotation.*;
|
||||
import me.totalfreedom.datura.Datura;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Info(name = "fuckoff", description = "You'll never even see it coming - repeatedly push players away from you until command is untoggled.", usage = "/fuckoff <on|off> [radius]")
|
||||
@Permissive(perm = "datura.fuckoff", onlyPlayers = true)
|
||||
@Completion(args = {"on", "off"}, index = 0)
|
||||
@Completion(args = {"[radius]"}, index = 1)
|
||||
public class FuckoffCommand extends Commander
|
||||
{
|
||||
private final Datura plugin = Shortcuts.provideModule(Datura.class);
|
||||
|
||||
/**
|
||||
* Initializes this command object. The provided {@link JavaPlugin} should be the plugin which contains the
|
||||
* command.
|
||||
* <p>
|
||||
* This constructor will automatically register all subcommands and completions for this command. It will also
|
||||
* automatically infer all required information from the provided {@link Info} and {@link Permissive} annotations.
|
||||
*
|
||||
* @param plugin The plugin which contains this command.
|
||||
*/
|
||||
public FuckoffCommand(@NotNull JavaPlugin plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Subcommand(permission = "datura.fuckoff", args = {String.class})
|
||||
public void fuckOff(final Player sender, final String toggle)
|
||||
{
|
||||
execute(sender, toggle, 15);
|
||||
}
|
||||
|
||||
@Subcommand(permission = "datura.fuckoff", args = {String.class, Integer.class})
|
||||
public void fuckOff(final Player sender, final String toggle, final Integer radius)
|
||||
{
|
||||
execute(sender, toggle, radius);
|
||||
}
|
||||
|
||||
private void execute(final Player sender, final String toggle, final int radius)
|
||||
{
|
||||
if (toggle.equalsIgnoreCase("on"))
|
||||
{
|
||||
plugin.getFuckoff().
|
||||
add(sender, radius);
|
||||
|
||||
sender.sendPlainMessage("FuckOff enabled.");
|
||||
} else if (toggle.equalsIgnoreCase("off"))
|
||||
{
|
||||
plugin.getFuckoff().
|
||||
remove(sender);
|
||||
|
||||
sender.sendPlainMessage("FuckOff disabled.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package me.totalfreedom.datura.features;
|
||||
|
||||
import me.totalfreedom.service.Service;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class Fuckoff extends Service
|
||||
{
|
||||
private final Map<UUID, Integer> players = new ConcurrentHashMap<>();
|
||||
|
||||
public Fuckoff()
|
||||
{
|
||||
super("fuckoff-service");
|
||||
}
|
||||
|
||||
public void add(final Player player, final int radius)
|
||||
{
|
||||
players.put(player.getUniqueId(), radius);
|
||||
}
|
||||
|
||||
public void remove(final Player player)
|
||||
{
|
||||
players.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
for (Map.Entry<UUID, Integer> entry : players.entrySet())
|
||||
{
|
||||
final var player = Bukkit.getPlayer(entry.getKey());
|
||||
|
||||
if (player == null)
|
||||
{
|
||||
players.remove(entry.getKey());
|
||||
continue;
|
||||
}
|
||||
|
||||
pushPlayers(player, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void pushPlayers(@NotNull final Player player, final int radius)
|
||||
{
|
||||
Bukkit.getOnlinePlayers()
|
||||
.stream()
|
||||
.filter(onlinePlayer -> onlinePlayer.getLocation().distanceSquared(player.getLocation()) < (radius * radius))
|
||||
.forEach(onlinePlayer -> {
|
||||
onlinePlayer.setVelocity(
|
||||
player.getLocation().toVector()
|
||||
.add(onlinePlayer.getLocation().toVector()).normalize().multiply(radius)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user