Skip to content

Commit

Permalink
Merge pull request #3 from GreenSurvivors/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
FireInstall authored Dec 5, 2023
2 parents b9229bf + 1d5e1f1 commit faa61f3
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 77 deletions.
2 changes: 1 addition & 1 deletion TodoList
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Hoppers (minecart hoppers too!) cannot take or put items, unless a [Redstone] ta

todo wiki
todo permission group support
todo make multi door opening/closing together configurable per sign
todo make config/langfiles update if version shipped with jar changes
todo better API
todo check what applies for access type / timer
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}
// Suppiled by Jenkins
ext.majorVersion = 2
ext.minorVersion = 2
ext.minorVersion = 3
ext.minecraftVersion = "1.20.1"

ext.buildNumber = System.env.BUILD_NUMBER == null ? "x" : "build" + "$System.env.BUILD_NUMBER"
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/greensurvivors/padlock/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.apache.commons.collections4.set.ListOrderedSet;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Sound;
Expand Down Expand Up @@ -49,6 +50,7 @@ public Command(@NotNull Padlock plugin) {
SUBCOMMANDS.add(new RemoveMember(plugin));
SUBCOMMANDS.add(new SetTimer(plugin));
SUBCOMMANDS.add(new SetAccessType(plugin));
SUBCOMMANDS.add(new SetConnected(plugin));
// admin sub commands
SUBCOMMANDS.add(new AddOwner(plugin));
SUBCOMMANDS.add(new RemoveOwner(plugin));
Expand Down Expand Up @@ -403,7 +405,7 @@ public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull org.bu
if (suggestionList != null) {
List<String> filteredList = new ArrayList<>();
for (String s : suggestionList) {
if (s.startsWith(args[args.length - 1])) {
if (StringUtils.startsWithIgnoreCase(s, args[args.length - 1])) {
filteredList.add(s);
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/de/greensurvivors/padlock/command/Info.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected boolean checkPermission(@NotNull Permissible permissible) {
}

@Override
protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args) { //todo this needs formatting and general glow up
protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args) { //todo this needs formatting and general glow up; connected info; payers seem to be broken
if (this.checkPermission(sender)) {
if (sender instanceof Player player) {
Sign sign = SignSelection.getSelectedSign(player);
Expand All @@ -84,16 +84,16 @@ protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] arg
SignLock.isMember(sign, player.getUniqueId())) {

// owners
Component component = plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_OWNERS);
Component component = plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_OWNERS).appendSpace();
for (String name : getNamesFromUUIDStrSet(SignLock.getUUIDs(sign, true, false))) {
component = component.append(Component.text(name));
component = component.append(Component.text(", "));
}

// members
component = component.append(Component.newline());
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_MEMBERS));
if (SignAccessType.getAccessType(sign, false) == SignAccessType.AccessType.PUBLIC) {
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_MEMBERS)).appendSpace();
if (SignAccessType.getAccessType(sign, false) != SignAccessType.AccessType.PUBLIC) {
for (String name : getNamesFromUUIDStrSet(SignLock.getUUIDs(sign, false, false))) {
component = component.append(Component.text(name));
component = component.append(Component.text(", "));
Expand All @@ -102,7 +102,7 @@ protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] arg

// access type
component = component.append(Component.newline());
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_ACCESS_TYPE));
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_ACCESS_TYPE)).appendSpace();

switch (SignAccessType.getAccessType(sign, false)) {
case PRIVATE ->
Expand All @@ -124,13 +124,13 @@ protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] arg
Long timer = SignTimer.getTimer(sign, false);
if (timer != null) {
component = component.append(Component.newline());
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_TIMER));
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_TIMER)).appendSpace();
component = component.append(Component.text(timer));
}

// expiration
component = component.append(Component.newline());
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_EXPIRED));
component = component.append(plugin.getMessageManager().getLang(MessageManager.LangPath.INFO_EXPIRED)).appendSpace();
component = component.append(Component.text(SignExpiration.isSignExpired(sign)));

plugin.getMessageManager().sendMessageWithPrefix(sender, component);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/greensurvivors/padlock/command/Password.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Password(@NotNull Padlock plugin) {

public static void onExternalCommand(char @NotNull [] password, @NotNull Player player) {
// check permission for passwords
if (player.hasPermission(PermissionManager.CMD_PASSWORD.getPerm())) {
if (player.hasPermission(PermissionManager.CMD_APPLY_PASSWORD.getPerm())) {

//get and check selected sign
Sign sign = SignSelection.getSelectedSign(player);
Expand Down Expand Up @@ -78,7 +78,7 @@ public static void onExternalCommand(char @NotNull [] password, @NotNull Player

@Override
protected boolean checkPermission(@NotNull Permissible permissible) {
return permissible.hasPermission(PermissionManager.CMD_PASSWORD.getPerm());
return permissible.hasPermission(PermissionManager.CMD_APPLY_PASSWORD.getPerm());
}

@Override
Expand Down
104 changes: 104 additions & 0 deletions src/main/java/de/greensurvivors/padlock/command/SetConnected.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package de.greensurvivors.padlock.command;

import de.greensurvivors.padlock.Padlock;
import de.greensurvivors.padlock.config.MessageManager;
import de.greensurvivors.padlock.config.PermissionManager;
import de.greensurvivors.padlock.impl.SignSelection;
import de.greensurvivors.padlock.impl.signdata.SignConnectedOpenable;
import de.greensurvivors.padlock.impl.signdata.SignLock;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.apache.commons.lang3.BooleanUtils;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Set;

public class SetConnected extends SubCommand {

protected SetConnected(@NotNull Padlock plugin) {
super(plugin);
}

@Override
protected boolean checkPermission(@NotNull Permissible permissible) {
return permissible.hasPermission(PermissionManager.CMD_SET_CONNECTED.getPerm());
}

@Override
protected @NotNull Set<String> getAliases() {
return Set.of("setconnected", "setc");
}

@Override
protected @NotNull Component getHelpText() {
return plugin.getMessageManager().getLang(MessageManager.LangPath.HELP_SET_CONNECTED);
}

@Override
protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args) {
if (this.checkPermission(sender)) {
if (sender instanceof Player player) {
if (args.length >= 2) {
Sign sign = SignSelection.getSelectedSign(player);

if (sign != null) {
//check for old Lockett(Pro) signs and try to update them
sign = Command.checkAndUpdateLegacySign(sign, player);
if (sign == null) {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SIGN_NEED_RESELECT);
return true;
}

// only admins and owners can change a signs properties
if (SignLock.isOwner(sign, player.getUniqueId()) ||
player.hasPermission(PermissionManager.ADMIN_EDIT.getPerm())) {
// get and check type from arg

Boolean shouldConnected = BooleanUtils.toBooleanObject(args[1]);

if (shouldConnected != null) {
// success!
SignConnectedOpenable.setConnected(sign, shouldConnected);
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_CONNECTED_SUCCESS,
Placeholder.component(MessageManager.PlaceHolder.ARGUMENT.getPlaceholder(), Component.text(shouldConnected)));
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NOT_A_BOOL,
Placeholder.unparsed(MessageManager.PlaceHolder.ARGUMENT.getPlaceholder(), args[1]));
return false;
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NOT_OWNER);
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SIGN_NOT_SELECTED);
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NOT_ENOUGH_ARGS);
return false;
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NOT_A_PLAYER);
return false;
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NO_PERMISSION);
}

return true;
}

@Override
protected @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull String[] args) {
if (this.checkPermission(sender) && args.length == 2) {
return List.of(Boolean.toString(true), Boolean.toString(false));
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static void onExternalCommand(char @NotNull [] newPassword, @NotNull Play

@Override
protected boolean checkPermission(@NotNull Permissible permissible) {
return permissible.hasPermission(PermissionManager.CMD_PASSWORD.getPerm());
return permissible.hasPermission(PermissionManager.CMD_SET_PASSWORD.getPerm());
}

@Override
Expand Down
46 changes: 32 additions & 14 deletions src/main/java/de/greensurvivors/padlock/command/SetTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected boolean checkPermission(@NotNull Permissible permissible) {
@Override
protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] args) {
if (sender instanceof Player player) {
if (sender.hasPermission(PermissionManager.CMD_SET_CREATED.getPerm())) {
if (sender.hasPermission(PermissionManager.CMD_SET_TIMER.getPerm())) {
if (args.length >= 2) {
Sign sign = SignSelection.getSelectedSign(player);

Expand All @@ -69,24 +69,42 @@ protected boolean onCommand(@NotNull CommandSender sender, @NotNull String[] arg
// note: writing every time element in one argument,
// would have the same effect as spreading them across multiple arguments.
// using the same time unit more than once is permitted.
long timerDuration = 0;
for (int i = 1; i < args.length; i++) {
timerDuration += MiscUtils.parsePeriod(args[i]);
Long timerDuration = null;

if (args.length == 2) {
try {
if (Integer.parseInt(args[1]) <= 0) {
timerDuration = -1L;
}
} catch (NumberFormatException ignored) {
}
}

if (timerDuration != 0) {
// success
SignTimer.setTimer(sign, timerDuration, true);
if (timerDuration == null) {
for (int i = 1; i < args.length; i++) {
Long period = MiscUtils.parsePeriod(args[i]);

if (period != null) {
if (timerDuration == null) {
timerDuration = 0L;
}

if (timerDuration > 0) {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_SUCCESS_ON,
Placeholder.component(MessageManager.PlaceHolder.TIME.getPlaceholder(), Component.text(timerDuration)));
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_SUCCESS_OFF);
timerDuration += period;
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_ERROR);
return false;
}
}
}

// success
SignTimer.setTimer(sign, timerDuration, true);

if (timerDuration > 0) {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_SUCCESS_ON,
Placeholder.component(MessageManager.PlaceHolder.TIME.getPlaceholder(), Component.text(timerDuration)));
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_ERROR);
return false;
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.SET_TIMER_SUCCESS_OFF);
}
} else {
plugin.getMessageManager().sendLang(sender, MessageManager.LangPath.NOT_OWNER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public enum LangPath {
ERROR_SIGN("sign.line.error", "[<dark_red>Error</dark_red>]"),
INVALID_SIGN("sign.line.invalid", "[Invalid]"),
PLAYER_NAME_ON_SIGN("sign.line.player-name", "<" + PlaceHolder.PLAYER.getPlaceholder() + ">"), // used for formatting displayed player names
MORE_USERS_ON_SIGN("sign.line.more-users", "[More Users]"), // not the same as the LEGACY_ADDITIONAL_SIGN line. This indicates that there are users that can't get displayed.

@Deprecated(forRemoval = true)
LEGACY_ADDITIONAL_SIGN("sign.legacy.additional", "[More Users]"),
Expand All @@ -298,6 +299,7 @@ public enum LangPath {
HELP_ADD_OWNER("cmd.help.add-owner"),
HELP_REMOVE_OWNER("cmd.help.remove-owner"),
HELP_SET_ACCESS_TYPE("cmd.help.set-access-type"),
HELP_SET_CONNECTED("cmd.help.set-connected"),
HELP_SET_PASSWORD("cmd.help.set-password"),
HELP_SET_TIMER("cmd.help.set-timer"),
HELP_DEBUG("cmd.help.debug"),
Expand Down Expand Up @@ -327,6 +329,7 @@ public enum LangPath {
PASSWORD_SAFETY_WARNING("cmd.password.safety-warning", "<dark_red>Warning: never use a password, you are using anywhere else! While I did everything I could for your safety, there <bold>ARE</bold> ways your password could get leaked!</dark_red>"),
PASSWORD_START_PROCESSING("cmd.password.start-processing"),
RELOAD_SUCCESS("cmd.reload.success"),
SET_CONNECTED_SUCCESS("cmd.set-connected.success"),

INFO_OWNERS("cmd.info.owners"),
INFO_MEMBERS("cmd.info.members"),
Expand All @@ -340,6 +343,7 @@ public enum LangPath {
NOT_A_PLAYER("cmd.error.not-a-player"),
NOT_ENOUGH_ARGS("cmd.error.not-enough-args"),
NOT_ACCESS_TYPE("cmd.error.not-access-type"),
NOT_A_BOOL("cmd.error.not-a-bool"),
CMD_USAGE("cmd.usage"),
CMD_NOT_A_SUBCOMMAND("cmd.not-a-subcommand"),

Expand Down
Loading

0 comments on commit faa61f3

Please sign in to comment.