Skip to content

Commit

Permalink
2.2.3
Browse files Browse the repository at this point in the history
+ Added tab completion for door names and ids
+ Add condition to check for door ownership
* Fixed a typo in the mythic mobs remove command
  • Loading branch information
rainbowdashlabs authored Sep 18, 2020
1 parent 4a45958 commit c4921cf
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 170 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.eldoria</groupId>
<artifactId>bigdoorsopener</artifactId>
<version>2.2.2</version>
<version>2.2.3</version>
<name>BigDoorsOpener</name>
<url>https://github.com/eldoriarpg/BigDoorOpener</url>
<description>Open and close doors automatically on certain conditions</description>
Expand Down
77 changes: 3 additions & 74 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,10 @@
# Big Door Opener

This is an add-on for the amazing plugin [Big Doors](https://www.spigotmc.org/resources/big-doors.58669/).
This is an add-on for the amazing plugin [Big Doors](https://www.spigotmc.org/resources/58669/).

It allows you to create doors, which open and close based on various conditions.


# Features
* Timed door. Define at which times doors should be open and closed.
* Closed door. A door which is always closed except when a player approaches it.
* Player approach. A closed door can open when a player approaches it.
* Permission door. A closed door will only open when a player with a specific permission approaches it.
Please see the [wiki](https://github.com/eldoriarpg/BigDoorOpener/wiki) for further Information.

# Setup
Simply drop the jar in your plugin folder.

Make sure you have [Big Doors](https://www.spigotmc.org/resources/big-doors.58669/) installed as well.

# Commands

Every door created will have a range of 10 blocks to open.

All commands have full tab completion support. So you can probably skip this part and start using it.
I highly recommend to not set an autoclose value or manage this door with redstone.

#### Create a timed door
`/bdo setTimed <doorId> <open> <close>`
This creates a new automatic door which opens and closes at the specific time.
It will open when a player approaches it. [See permissions to change this.](#Door-with-permission)

*You can enter a time (E.g. 6:30), or a tick amount (E.g. 500) as time.*

![timed door](http://chojo.u.catgirlsare.sexy/vtvJ5gPK.gif)

#### Create a closed door
`/bdo setClosed <doorId>`
This creates a closed door which only opens on player approach.

![closed door](http://chojo.u.catgirlsare.sexy/2aZr_Ngq.gif)

#### Set the approach range
`/bdo setRange <doorId> <range>`
The door will open if a player is inside this range around the door.
The center is the center of the door.
*To disable approach opening set the range to 0*

#### Invert open
`/bdo invertOpen <doorId> <true|false>`
This inverts the state of the door.
*Big Doors assumes that a created door is in closed state. If you created it in open state you need to set this to `true`*

#### Door with permission
`/bdo requiresPermission <doorId> <true|false|permission>`
This sets a permission for the door.
True will use the permission `bdo.use.<doorId>`.
You can also enter your own permission.
To remove the permission set this to `false`.

If a permission is set, the door will only open for players with this permission, when it's closed.

#### Unregister a door
`/bdo unregister <doorId>`
Removes a door. It is than no longer managed by this plugin.

#### Door info
`/bdo info <doorId>`
This will give you information about a door.

#### Reload plugin
`/bdo about`
This will reload the plugin with the config.

#### About
`/bdo about`
Some information about the plugin.

# Permissions

To use this plugin you will need `bdo.use`

To reload this plugin you wil need `bdo.reload`
The latest stable release can be found on [spigot](https://www.spigotmc.org/resources/80805/)
12 changes: 9 additions & 3 deletions src/main/java/de/eldoria/bigdoorsopener/BigDoorsOpener.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import de.eldoria.bigdoorsopener.doors.conditions.location.Proximity;
import de.eldoria.bigdoorsopener.doors.conditions.location.Region;
import de.eldoria.bigdoorsopener.doors.conditions.location.SimpleRegion;
import de.eldoria.bigdoorsopener.doors.conditions.permission.DoorPermission;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.MythicMob;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission;
import de.eldoria.bigdoorsopener.doors.conditions.permission.PermissionNode;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Placeholder;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Weather;
Expand Down Expand Up @@ -108,6 +109,10 @@ public static BigDoors getBigDoors() {
return instance.doors;
}

public static Localizer getLocalizer() {
return instance.localizer;
}

@Override
public void onDisable() {
super.onDisable();
Expand Down Expand Up @@ -156,7 +161,7 @@ public void onEnable() {
scheduler.scheduleSyncRepeatingTask(this, doorChecker, 100, 1);

registerCommand("bigdoorsopener",
new BigDoorsOpenerCommand(this, commander, config, localizer, doorChecker, registerInteraction));
new BigDoorsOpenerCommand(this, doors, config, localizer, doorChecker, registerInteraction));
}

if (initialized) {
Expand Down Expand Up @@ -259,7 +264,8 @@ private void buildSerializer() {
ConfigurationSerialization.registerClass(Proximity.class, "proximityCondition");
ConfigurationSerialization.registerClass(Region.class, "regionCondition");
ConfigurationSerialization.registerClass(SimpleRegion.class, "simpleRegionCondition");
ConfigurationSerialization.registerClass(Permission.class, "permissionCondition");
ConfigurationSerialization.registerClass(PermissionNode.class, "permissionCondition");
ConfigurationSerialization.registerClass(DoorPermission.class, "doorPermissionCondition");
ConfigurationSerialization.registerClass(Time.class, "timeCondition");
ConfigurationSerialization.registerClass(Weather.class, "weatherCondition");
ConfigurationSerialization.registerClass(Placeholder.class, "placeholderCondition");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import de.eldoria.bigdoorsopener.doors.conditions.location.Proximity;
import de.eldoria.bigdoorsopener.doors.conditions.location.Region;
import de.eldoria.bigdoorsopener.doors.conditions.location.SimpleRegion;
import de.eldoria.bigdoorsopener.doors.conditions.permission.DoorPermission;
import de.eldoria.bigdoorsopener.doors.conditions.permission.PermissionNode;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.MythicMob;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Placeholder;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Weather;
import de.eldoria.bigdoorsopener.listener.registration.InteractionRegistrationObject;
import de.eldoria.bigdoorsopener.listener.registration.RegisterInteraction;
import de.eldoria.bigdoorsopener.scheduler.BigDoorsAdapter;
import de.eldoria.bigdoorsopener.scheduler.DoorChecker;
import de.eldoria.bigdoorsopener.util.C;
import de.eldoria.bigdoorsopener.util.CachingJSEngine;
Expand All @@ -45,7 +47,7 @@
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import nl.pim16aap2.bigDoors.Commander;
import nl.pim16aap2.bigDoors.BigDoors;
import nl.pim16aap2.bigDoors.Door;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -77,7 +79,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class BigDoorsOpenerCommand implements TabExecutor {
public class BigDoorsOpenerCommand extends BigDoorsAdapter implements TabExecutor {
private static final CachingJSEngine ENGINE;
// Tabcomplete utils
private static final String[] CONDITION_TYPES;
Expand All @@ -86,7 +88,6 @@ public class BigDoorsOpenerCommand implements TabExecutor {
private static final String[] WEATHER_TYPE;
private static final String[] EVALUATOR_TYPES;
private final BigDoorsOpener plugin;
private final Commander commander;
private final Config config;
private final Localizer localizer;
private final DoorChecker doorChecker;
Expand All @@ -95,15 +96,15 @@ public class BigDoorsOpenerCommand implements TabExecutor {
private final RegionContainer regionContainer;
private final BukkitAudiences bukkitAudiences;

private final Cache<String, List<String>> pluginCache = C.getExpiringCache(30, TimeUnit.SECONDS);
private final Cache<String, List<?>> pluginCache = C.getExpiringCache(30, TimeUnit.SECONDS);

static {
ENGINE = BigDoorsOpener.JS();
CONDITION_TYPES = Arrays.stream(ConditionType.values())
.map(v -> v.conditionName)
.toArray(String[]::new);
CONDITION_GROUPS = Arrays.stream(ConditionType.ConditionGroup.values())
.map(v -> v.name().toLowerCase())
.map(v -> v.name().toLowerCase().replace("_", ""))
.toArray(String[]::new);
PROXIMITY_FORM = Arrays.stream(Proximity.ProximityForm.values())
.map(v -> v.name().toLowerCase())
Expand All @@ -117,10 +118,10 @@ public class BigDoorsOpenerCommand implements TabExecutor {
}


public BigDoorsOpenerCommand(BigDoorsOpener plugin, Commander commander, Config config, Localizer localizer,
public BigDoorsOpenerCommand(BigDoorsOpener plugin, BigDoors doors, Config config, Localizer localizer,
DoorChecker doorChecker, RegisterInteraction registerInteraction) {
super(doors, localizer);
this.plugin = plugin;
this.commander = commander;
this.config = config;
this.localizer = localizer;
messageSender = MessageSender.get(plugin);
Expand Down Expand Up @@ -597,16 +598,32 @@ public boolean register(PlayerInteractEvent event) {
});
break;
// permission
case PERMISSION:
case PERMISSION_NODE:
if (argumentsInvalid(player, conditionArgs, 1,
"<" + localizer.getMessage("syntax.doorId") + "> <"
+ localizer.getMessage("syntax.condition") + "> <"
+ localizer.getMessage("tabcomplete.permissionNode") + ">")) {
return true;
}

conditionChain.setPermission(new PermissionNode(conditionArgs[0]));
messageSender.sendMessage(player, localizer.getMessage("setCondition.permissionNode"));
break;
case DOOR_PERMISSION:
if (argumentsInvalid(player, conditionArgs, 1,
"<" + localizer.getMessage("syntax.doorId") + "> <"
+ localizer.getMessage("syntax.condition") + "> <"
+ localizer.getMessage("tabcomplete.permission") + ">")) {
+ localizer.getMessage("tabcomplete.doorPermission") + ">")) {
return true;
}

conditionChain.setPermission(new Permission(conditionArgs[0]));
messageSender.sendMessage(player, localizer.getMessage("setCondition.permission"));
int i = DoorPermission.parsePermissionLevel(conditionArgs[0]);
if (i < 0) {
messageSender.sendError(player, localizer.getMessage("error.invalidAccessLevel"));
return true;
}
conditionChain.setPermission(new DoorPermission(i));
messageSender.sendMessage(player, localizer.getMessage("setCondition.doorPermission"));
break;
case TIME:
if (argumentsInvalid(player, conditionArgs, 2,
Expand Down Expand Up @@ -1315,13 +1332,13 @@ private boolean list(Player player) {

if (player.hasPermission(Permissions.ACCESS_ALL)) {
for (ConditionalDoor value : doors.values()) {
Door door = commander.getDoor(String.valueOf(value.getDoorUID()), null);
Door door = getDoor(null, String.valueOf(value.getDoorUID()));
builder.append(value.getDoorUID()).append(" | ")
.append("§6").append(door.getName()).append("§r")
.append(" (").append(door.getWorld().getName()).append(")\n");
}
} else {
List<Door> registeredDoors = commander.getDoors(player.getUniqueId().toString(), null)
List<Door> registeredDoors = getDoors(player, null)
.stream()
.filter(d -> doors.containsKey(d.getDoorUID()))
.collect(Collectors.toList());
Expand Down Expand Up @@ -1419,7 +1436,7 @@ private Pair<ConditionalDoor, Door> getConditionalPlayerDoor(String doorUID, Pla
private Door getPlayerDoor(String doorUID, Player player) {
if (player == null) {
// requester is console. should always have access to all doors.
Door door = commander.getDoor(doorUID, null);
Door door = getDoor(null, doorUID);
if (door == null) {
messageSender.sendError(null, localizer.getMessage("error.doorNotFound"));
return null;
Expand All @@ -1428,11 +1445,11 @@ private Door getPlayerDoor(String doorUID, Player player) {
}

// sender id not console. retrieve door of player.
ArrayList<Door> doors = commander.getDoors(player.getUniqueId().toString(), doorUID);
List<Door> doors = getDoors(player, doorUID);

if (doors.isEmpty()) {
// door is null. check if door exists anyway
Door door = commander.getDoor(doorUID, null);
Door door = getDoor(null, doorUID);
if (door == null) {
messageSender.sendError(player, localizer.getMessage("error.doorNotFound"));
return null;
Expand Down Expand Up @@ -1568,9 +1585,14 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return Collections.singletonList("<" + localizer.getMessage("tabcomplete.regionName") + ">");
}
break;
case PERMISSION:
case PERMISSION_NODE:
if (args.length == 4) {
return Collections.singletonList("<" + localizer.getMessage("tabcomplete.permissionNode") + ">");
}
break;
case DOOR_PERMISSION:
if (args.length == 4) {
return Collections.singletonList("<" + localizer.getMessage("tabcomplete.permission") + ">");
return ArrayUtil.startingWithInArray(args[3], new String[] {"owner", "editor", "user"}).collect(Collectors.toList());
}
break;
case TIME:
Expand All @@ -1597,9 +1619,8 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case MYTHIC_MOBS:
List<String> mythicMobs;
try {
mythicMobs = pluginCache.get("mythicMobs", () -> MythicMobs.inst()
mythicMobs = (List<String>) pluginCache.get("mythicMobs", () -> MythicMobs.inst()
.getMobManager().getMobTypes()

.parallelStream()
.map(m -> m.getInternalName())
.collect(Collectors.toList()));
Expand Down Expand Up @@ -1714,21 +1735,40 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return Collections.emptyList();
}

@SuppressWarnings("unchecked")
public List<String> getDoorCompletion(Player player, String name) {
if (player == null) {
return Collections.singletonList("<" + localizer.getMessage("syntax.doorId") + ">");
}
List<String> doorNames;
List<Door> doors;
try {
doorNames = pluginCache.get(player.getName() + "doors",
() -> commander.getDoors(player.getUniqueId().toString(), null)
.stream()
.map(Door::getName)
.collect(Collectors.toList()));
doors = (List<Door>) pluginCache.get("doors",
() -> new ArrayList<>(getDoors()));
} catch (ExecutionException e) {
plugin.getLogger().log(Level.WARNING, "Could not build tab completion cache for door names.", e);
return Collections.singletonList("<" + localizer.getMessage("syntax.doorId") + ">");
}
List<String> doorNames;
try {
doorNames = (List<String>) pluginCache.get(player.getName() + "doors",
() -> {
if (player.hasPermission(Permissions.ACCESS_ALL)) {
return doors.stream()
.map(d -> d.getPlayerUUID().equals(player.getUniqueId())
? d.getName() : String.valueOf(d.getDoorUID()))
.collect(Collectors.toList());
}

// Map door names for doors where the player is the creator and can use the door name
return getDoors(player).stream()
.map(d -> d.getPermission() == 0 ? d.getName() : String.valueOf(d.getDoorUID()))
.collect(Collectors.toList());
});
} catch (
ExecutionException e) {
plugin.getLogger().log(Level.WARNING, "Could not build tab completion cache for door names.", e);
return Collections.singletonList("<" + localizer.getMessage("syntax.doorId") + ">");
}

return ArrayUtil.startingWithInArray(name,
doorNames.toArray(new String[0]))
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/de/eldoria/bigdoorsopener/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import de.eldoria.bigdoorsopener.doors.ConditionalDoor;
import de.eldoria.bigdoorsopener.doors.conditions.ConditionChain;
import de.eldoria.bigdoorsopener.doors.conditions.location.Proximity;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission;
import de.eldoria.bigdoorsopener.doors.conditions.permission.PermissionNode;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time;
import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -108,7 +108,7 @@ private void updateVersion0() {
ConditionChain conditionChain = cD.getConditionChain();

if (tD.getPermission() != null && !tD.getPermission().isEmpty()) {
conditionChain.setPermission(new Permission(tD.getPermission()));
conditionChain.setPermission(new PermissionNode(tD.getPermission()));
log.info("Adding permission condition.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import de.eldoria.bigdoorsopener.doors.ConditionalDoor;
import de.eldoria.bigdoorsopener.doors.conditions.item.Item;
import de.eldoria.bigdoorsopener.doors.conditions.location.Location;
import de.eldoria.bigdoorsopener.doors.conditions.permission.Permission;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.MythicMob;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Permission;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Placeholder;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Time;
import de.eldoria.bigdoorsopener.doors.conditions.standalone.Weather;
Expand Down
Loading

0 comments on commit c4921cf

Please sign in to comment.