Overhaul of Patchwork and Registration system, fix-up for all plugin.yml files and removal of .negates(0 and .value() from DefaultNodes in turn for the .expiry() system removing the redundancies. (#21)

Co-authored-by: eva <66324759+evax64@users.noreply.github.com>
This commit is contained in:
Eva
2023-08-11 19:15:36 +01:00
committed by GitHub
parent 368f3cae12
commit 3e8c63221d
24 changed files with 113 additions and 158 deletions

View File

@ -6,7 +6,7 @@ import fns.datura.punishment.Cager;
import fns.datura.punishment.Halter;
import fns.datura.punishment.Locker;
import fns.datura.sql.MySQL;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Registration;
import fns.patchwork.service.SubscriptionProvider;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@ -18,7 +18,7 @@ public class Datura extends JavaPlugin
// Punishment
private final Halter halter = new Halter();
private final Locker locker = new Locker();
private final Cager cager = new Cager();
private Cager cager;
// Features
private final CommandSpy commandSpy = new CommandSpy();
@ -27,28 +27,22 @@ public class Datura extends JavaPlugin
@Override
public void onEnable()
{
Patchwork.getInstance()
.getRegistrations()
.getModuleRegistry()
.addModule(this);
cager = new Cager(this);
Patchwork.getInstance()
.getRegistrations()
.getServiceTaskRegistry()
Registration.getServiceTaskRegistry()
.registerService(SubscriptionProvider.syncService(this, locker));
Patchwork.getInstance()
.getRegistrations()
.getServiceTaskRegistry()
Registration.getServiceTaskRegistry()
.registerService(SubscriptionProvider.syncService(this, cager));
Patchwork.getInstance()
.getRegistrations()
.getServiceTaskRegistry()
Registration.getServiceTaskRegistry()
.registerService(SubscriptionProvider.syncService(this, fuckoff));
Bukkit.getPluginManager()
.registerEvents(halter, this);
Bukkit.getPluginManager()
.registerEvents(commandSpy, this);
Registration.getModuleRegistry()
.addModule(this);
}
public MySQL getSQL()

View File

@ -1,6 +1,7 @@
package fns.datura.cmd;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.command.Commander;
import fns.patchwork.command.annotation.Base;
import fns.patchwork.command.annotation.Info;
@ -38,11 +39,11 @@ public class AdminChatCommand extends Commander
final Player player = (Player) sender;
Patchwork.getInstance()
Shortcuts.provideModule(Patchwork.class)
.getAdminChatDisplay()
.toggleChat(player);
final boolean toggled = Patchwork.getInstance()
final boolean toggled = Shortcuts.provideModule(Patchwork.class)
.getAdminChatDisplay()
.isToggled(player);
@ -57,7 +58,7 @@ public class AdminChatCommand extends Commander
@Subcommand(permission = "patchwork.adminchat", args = {String.class})
public void sendMessage(final CommandSender sender, final String message)
{
Patchwork.getInstance()
Shortcuts.provideModule(Patchwork.class)
.getAdminChatDisplay()
.adminChatMessage(sender, Component.text(message));
}

View File

@ -51,7 +51,7 @@ public class ClearDropsCommand extends Commander
}
final Player player = (Player) sender;
Patchwork.getInstance()
Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L)
.execute(() ->
@ -73,7 +73,7 @@ public class ClearDropsCommand extends Commander
@Subcommand(permission = "datura.cleardrops", args = {World.class})
public void clearDrops(final CommandSender sender, final World world)
{
Patchwork.getInstance()
Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.delayedExecutor(Shortcuts.provideModule(Datura.class), 20 * 10L)
.execute(() ->

View File

@ -7,30 +7,26 @@ public class DefaultNodes
{
public static final Node OP = new PermissionNodeBuilder()
.key("freedom.master_key")
.value(true)
.expiry(-1)
.type(NodeType.PERMISSION)
.negated(false)
.wildcard(true)
.build();
public static final Node NON_OP = new PermissionNodeBuilder()
.key("freedom.default")
.value(true)
.expiry(-1)
.type(NodeType.PERMISSION)
.negated(false)
.wildcard(false)
.build();
public static final Node ALL = new PermissionNodeBuilder()
.key("*")
.value(true)
.expiry(-1)
.type(NodeType.PERMISSION)
.negated(false)
.wildcard(true)
.build();
public static final Node NONE = new PermissionNodeBuilder()
.key("freedom.none")
.value(true)
.expiry(-1)
.type(NodeType.PERMISSION)
.negated(false)
.wildcard(false)
.build();

View File

@ -1,6 +1,7 @@
package fns.datura.perms;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.security.Group;
import fns.patchwork.security.Node;
import java.util.HashSet;
@ -40,7 +41,7 @@ public class FreedomGroup implements Group
this.isDefault = isDefault;
this.isHidden = isHidden;
this.permissions = new HashSet<>();
this.attachment = new PermissionAttachment(Patchwork.getInstance(), this);
this.attachment = new PermissionAttachment(Shortcuts.provideModule(Patchwork.class), this);
}
@Override

View File

@ -3,6 +3,8 @@ package fns.datura.perms;
import fns.datura.Datura;
import fns.datura.user.SimpleUserData;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Registration;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.security.Node;
import fns.patchwork.user.User;
import fns.patchwork.user.UserData;
@ -41,11 +43,7 @@ public class FreedomUser implements User
this.permissions = new HashSet<>();
this.displayName = player.displayName();
final Datura datura = Patchwork.getInstance()
.getRegistrations()
.getModuleRegistry()
.getProvider(Datura.class)
.getModule();
final Datura datura = Shortcuts.provideModule(Datura.class);
UserData data = SimpleUserData.fromSQL(datura.getSQL(), uuid.toString());
@ -56,8 +54,7 @@ public class FreedomUser implements User
this.userData = data;
Patchwork.getInstance()
.getRegistrations()
Registration
.getUserRegistry()
.registerUserData(this, userData);
}
@ -96,7 +93,7 @@ public class FreedomUser implements User
public boolean addPermission(final Node node)
{
final boolean value = !node.isTemporary() || node.isExpired();
final PermissionAttachment attachment = addAttachment(Patchwork.getInstance(), node.key(), value);
final PermissionAttachment attachment = addAttachment(Shortcuts.provideModule(Patchwork.class), node.key(), value);
bukkitAttachments.put(node, attachment);
return permissions().add(node);
}

View File

@ -1,5 +1,6 @@
package fns.datura.punishment;
import fns.datura.Datura;
import fns.patchwork.base.Patchwork;
import fns.patchwork.service.Service;
import fns.patchwork.utils.ShapeUtils;
@ -20,18 +21,20 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import javax.sound.midi.Patch;
public class Cager extends Service
{
private final Set<UUID> cagedPlayers;
private final Map<UUID, Location> cageLocations;
public Cager()
public Cager(final Datura datura)
{
super("cager-service");
this.cagedPlayers = new HashSet<>();
this.cageLocations = new HashMap<>();
Bukkit.getPluginManager()
.registerEvents(new CageListener(), Patchwork.getInstance());
.registerEvents(new CageListener(), datura);
}
/**

View File

@ -1,6 +1,7 @@
package fns.datura.punishment;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.service.Service;
import java.util.HashSet;
import java.util.Set;
@ -34,7 +35,7 @@ public class Locker extends Service
@Override
public void tick()
{
lockedPlayers.removeIf(uuid -> !Patchwork.getInstance()
lockedPlayers.removeIf(uuid -> !Shortcuts.provideModule(Patchwork.class)
.getServer()
.getOfflinePlayer(uuid)
.isOnline());

View File

@ -1,6 +1,7 @@
package fns.datura.sql;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.sql.SQL;
import fns.patchwork.utils.container.Identity;
import java.sql.Connection;
@ -74,7 +75,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to prepare statement: "
+ query + "\n", ex);
}
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -91,7 +92,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to connect to the database: "
+ url.toString() + "\n", ex);
}
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -111,7 +112,7 @@ public class MySQL implements SQL
"Failed to retrieve a result set from query: "
+ query + "\n", ex);
}
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -130,7 +131,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to execute update: "
+ query + "\n", ex);
}
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -149,7 +150,7 @@ public class MySQL implements SQL
throw new CompletionException("Failed to execute statement: "
+ query + "\n", ex);
}
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -193,7 +194,7 @@ public class MySQL implements SQL
ex);
}
return null;
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -202,7 +203,7 @@ public class MySQL implements SQL
final String key, final Identity identity)
{
return executeUpdate("UPDATE ? SET ? = ? WHERE ? = ?", table, column, value, key, identity.getId())
.thenApplyAsync(result -> result > 0, Patchwork.getInstance()
.thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}
@ -210,7 +211,7 @@ public class MySQL implements SQL
public CompletableFuture<Boolean> deleteRow(final String table, final String key, final Identity identity)
{
return executeUpdate("DELETE FROM ? WHERE ? = ?", table, key, identity.getId())
.thenApplyAsync(result -> result > 0, Patchwork.getInstance()
.thenApplyAsync(result -> result > 0, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync());
}

View File

@ -3,6 +3,8 @@ package fns.datura.user;
import fns.datura.event.UserDataUpdateEvent;
import fns.datura.perms.FreedomUser;
import fns.patchwork.base.Patchwork;
import fns.patchwork.base.Registration;
import fns.patchwork.base.Shortcuts;
import fns.patchwork.display.adminchat.AdminChatFormat;
import fns.patchwork.security.Group;
import fns.patchwork.sql.SQL;
@ -38,7 +40,7 @@ public class SimpleUserData implements UserData
this.username = player.getName();
this.user = new FreedomUser(player);
Patchwork.getInstance()
Shortcuts.provideModule(Patchwork.class)
.getEventBus()
.addEvent(event);
}
@ -84,8 +86,7 @@ public class SimpleUserData implements UserData
throw new IllegalStateException("Player should be online but they are not!");
final User user = new FreedomUser(player);
final Group group = Patchwork.getInstance()
.getRegistrations()
final Group group = Registration
.getGroupRegistry()
.getGroup(g);
@ -116,7 +117,7 @@ public class SimpleUserData implements UserData
if (player == null) throw new IllegalStateException("Player should be online but they are not!");
return new SimpleUserData(player);
}, Patchwork.getInstance()
}, Shortcuts.provideModule(Patchwork.class)
.getExecutor()
.getAsync())
.join();

View File

@ -1,5 +1,6 @@
name: Datura
main: me.totalfreedom.datura.Datura
main: fns.datura.Datura
api-version: 1.20
version: 1.0.0
author: TotalFreedom
description: Data Manager for the Freedom Network Suite