Skip to content

Commit

Permalink
Add maxSizeOfElevator & whitelist to the config.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed Sep 9, 2024
1 parent d1ffb57 commit 863e24b
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
import com.andrew121410.mc.world16elevators.utils.MemoryHolder;
import com.andrew121410.mc.world16elevators.utils.OtherPlugins;
import com.andrew121410.mc.world16utils.updater.UpdateManager;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.List;

public final class World16Elevators extends JavaPlugin {

private static World16Elevators instance;
Expand All @@ -18,19 +21,18 @@ public final class World16Elevators extends JavaPlugin {
private OtherPlugins otherPlugins;
private MemoryHolder memoryHolder;

// Global Config
private boolean chunkSmartManagement = false;
private int maxSizeOfElevator;
private List<String> elevatorCreationWhitelist;

@Override
public void onEnable() {
instance = this;
this.otherPlugins = new OtherPlugins(this);
this.memoryHolder = new MemoryHolder();

this.getConfig().options().copyDefaults(true);
this.saveConfig();
this.reloadConfig();

this.chunkSmartManagement = this.getConfig().getBoolean("ChunkSmartManagement");
handleConfig();

this.elevatorManager = new ElevatorManager(this);
this.elevatorManager.loadAllElevatorControllers();
Expand All @@ -45,6 +47,27 @@ public void onEnable() {
UpdateManager.registerUpdater(this, new com.andrew121410.mc.world16elevators.Updater(this));
}

private void handleConfig() {
saveDefaultConfig(); // Saves the default config.yml with comments if config.yml doesn't exist
this.getConfig().options().copyDefaults(true); // Ensures all defaults are in place
this.saveConfig(); // Saves the config again
this.reloadConfig(); // Reloads the config, including any new defaults

this.chunkSmartManagement = this.getConfig().getBoolean("ChunkSmartManagement");
this.maxSizeOfElevator = this.getConfig().getInt("maxSizeOfElevator");

// Elevator Creation Whitelist
ConfigurationSection whitelistSection = this.getConfig().getConfigurationSection("whitelist");
if (whitelistSection != null) {
boolean isEnable = whitelistSection.getBoolean("enabled");
if (isEnable) {
this.elevatorCreationWhitelist = whitelistSection.getStringList("players");
}else {
this.elevatorCreationWhitelist = null;
}
}
}

@Override
public void onDisable() {
this.elevatorManager.saveAllElevators();
Expand Down Expand Up @@ -77,4 +100,12 @@ public ElevatorManager getElevatorManager() {
public boolean isChunkSmartManagement() {
return chunkSmartManagement;
}

public int getMaxSizeOfElevator() {
return maxSizeOfElevator;
}

public List<String> getElevatorCreationWhitelist() {
return elevatorCreationWhitelist;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
player.sendMessage(Translate.color("&bYou don't have permission to use this command."));
return true;
}

// Elevator Creation Whitelist
if (this.plugin.getElevatorCreationWhitelist() != null) {
if (!this.plugin.getElevatorCreationWhitelist().contains(player.getName())) {
player.sendMessage(Translate.miniMessage("<red>You are not whitelisted to create an elevator controller."));
return true;
}
}

String controllerName = args[2].toLowerCase();

if (elevatorControllerMap.get(controllerName) != null) {
Expand Down Expand Up @@ -160,6 +169,14 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}

// Elevator Creation Whitelist
if (this.plugin.getElevatorCreationWhitelist() != null) {
if (!this.plugin.getElevatorCreationWhitelist().contains(player.getName())) {
player.sendMessage(Translate.miniMessage("<red>You are not whitelisted to create an elevator."));
return true;
}
}

if (args.length == 4) {
Block blockPlayerIsLookingAt = PlayerUtils.getBlockPlayerIsLookingAt(player);
ElevatorArguments eleArgs = getElevatorArguments(args, 2);
Expand All @@ -171,6 +188,13 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}

// Check the volume of the region to make sure it's not bigger than maxSizeOfElevator
int maxSizeOfElevator = this.plugin.getMaxSizeOfElevator();
if (region.getVolume() > maxSizeOfElevator) {
player.sendMessage(Translate.miniMessage("<red>The region you selected is too big. The max size is: <white>" + maxSizeOfElevator));
return true;
}

ElevatorController elevatorController = eleArgs.getElevatorController();
if (elevatorController == null) {
player.sendMessage(Translate.miniMessage("<red>Elevator controller was not found."));
Expand Down Expand Up @@ -967,6 +991,21 @@ public void run() {
} else {
player.sendMessage(Translate.color("&6/elevator boundingbox &e<Controller> &9<Elevator> &eshow/shift &3<y>"));
}
} else if (args[0].equalsIgnoreCase("volume")) { // /elevator volume
if (!player.hasPermission("world16elevators.volume")) {
player.sendMessage(Translate.color("&bYou don't have permission to use this command."));
return true;
}

BoundingBox region = this.plugin.getOtherPlugins().getWorld16Utils().getClassWrappers().getWorldEdit().getRegion(player);

if (region == null) {
player.sendMessage(Translate.miniMessage("<red>You need to select a region with WorldEdit."));
return true;
}

double volume = region.getVolume();
player.sendMessage(Translate.miniMessage("<green>The volume of the region is: <white>" + volume));
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ElevatorTab(World16Elevators plugin) {
tabCompleteList.add("teleport");
tabCompleteList.add("realign");
tabCompleteList.add("boundingbox");
tabCompleteList.add("volume");
this.elevatorControllerMap = this.plugin.getMemoryHolder().getElevatorControllerMap();
this.soundList = new ArrayList<>();
for (Sound value : Sound.values()) {
Expand Down
18 changes: 17 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
ChunkSmartManagement: false
# When set to true, it will load elevators if the chunk they are in is loaded, and unload them if the chunk is unloaded.
ChunkSmartManagement: false

# Maximum volume of the elevator bounding box.
# Change this value to set the max size limit of an elevator.
# Use /elevator volume with WorldEdit to find the volume of a selected WorldEdit region.
# Adjust maxSizeOfElevator based on the volume you get from /elevator volume, to fit your needs.
maxSizeOfElevator: 50

# Only certain players can create elevators.
# If enabled, only players in the whitelist can create elevators, no matter if they have the permission or even if they are OP.
whitelist:
enabled: false
players:
- "player1"
- "player2"
- "player3"

0 comments on commit 863e24b

Please sign in to comment.