-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from GreenSurvivors/dev
Dev
- Loading branch information
Showing
22 changed files
with
304 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/de/greensurvivors/padlock/command/SetConnected.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.