Skip to content

Commit

Permalink
Added config values for enabling group system and inactivity interval
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinnazeyy committed Sep 30, 2021
1 parent 16b14c4 commit 8c7a7ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

package com.alpsbte.plotsystem.commands.plot;

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.commands.BaseCommand;
import com.alpsbte.plotsystem.commands.SubCommand;
import com.alpsbte.plotsystem.core.config.ConfigPaths;
import com.alpsbte.plotsystem.utils.Invitation;
import com.alpsbte.plotsystem.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;

import java.sql.SQLException;
import java.util.logging.Level;
Expand All @@ -43,7 +46,8 @@ public CMD_Plot_Invite(BaseCommand baseCommand) {
@Override
public void onCommand(CommandSender sender, String[] args) {
if (args.length > 0) {
if (getPlayer(sender) != null) {
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
if (getPlayer(sender) != null && config.getBoolean(ConfigPaths.ENABLE_GROUP_SUPPORT)) {
Invitation invite = null;
for (Invitation item : Invitation.invitationsList) {
if (item.invitee == getPlayer(sender)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@

public abstract class ConfigPaths {

// General Behaviour
public static final String SPAWN_WORLD = "spawn-world";
public static final String CHECK_FOR_UPDATES = "check-for-updates";
public static final String ENABLE_SCORE_REQUIREMENT = "enable-score-requirement";
public static final String DEV_MODE = "dev-mode";
public static final String INACTIVITY_INTERVAL = "inactivity-interval";
public static final String ENABLE_GROUP_SUPPORT = "enable-group-support";

private static final String SYNC_FTP_FILES = "sync-ftp-files.";
public static final String SYNC_FTP_FILES_ENABLED = SYNC_FTP_FILES + "enabled";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package com.alpsbte.plotsystem.core.menus;

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.config.ConfigPaths;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.PlotHandler;
Expand All @@ -34,6 +36,7 @@
import com.alpsbte.plotsystem.utils.items.builder.LoreBuilder;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.ipvp.canvas.mask.BinaryMask;
import org.ipvp.canvas.mask.Mask;
Expand Down Expand Up @@ -107,7 +110,8 @@ protected void setMenuItemsAsync() {
// Set plot members item
try {
if (!plot.isReviewed()) {
if (getMenuPlayer() == plot.getPlotOwner().getPlayer() || getMenuPlayer().hasPermission("plotsystem.admin")) {
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
if ((getMenuPlayer() == plot.getPlotOwner().getPlayer() || getMenuPlayer().hasPermission("plotsystem.admin")) && config.getBoolean(ConfigPaths.ENABLE_GROUP_SUPPORT)) {
getMenu().getSlot(22)
.setItem(new ItemBuilder(Utils.getItemHead(Utils.CustomHead.ADD_BUTTON))
.setName("§b§lManage Members").setLore(new LoreBuilder()
Expand Down Expand Up @@ -174,7 +178,8 @@ protected void setItemClickEventsAsync() {
try {
if (!plot.isReviewed()) {
if (plot.getStatus() == Status.unfinished) {
if (clickPlayer == plot.getPlotOwner().getPlayer() || clickPlayer.hasPermission("plotsystem.admin")) {
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
if ((getMenuPlayer() == plot.getPlotOwner().getPlayer() || getMenuPlayer().hasPermission("plotsystem.admin")) && config.getBoolean(ConfigPaths.ENABLE_GROUP_SUPPORT)) {
clickPlayer.closeInventory();
new PlotMemberMenu(plot,clickPlayer);
} else if (plot.getPlotMembers().stream().anyMatch(m -> m.getUUID().equals(getMenuPlayer().getUniqueId()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ public static void checkPlotsForLastActivity() {
Bukkit.getScheduler().runTaskTimerAsynchronously(PlotSystem.getPlugin(), () -> {
try {
List<Plot> plots = getPlots(Status.unfinished);
long millisIn14Days = 14L * 24 * 60 * 60 * 1000; // Remove all plots which have no activity for the last 14 days
FileConfiguration config = PlotSystem.getPlugin().getConfigManager().getConfig();
long millisInDays = config.getLong(ConfigPaths.INACTIVITY_INTERVAL) * 24 * 60 * 60 * 1000; // Remove all plots which have no activity for the last x days

for(Plot plot : plots) {
if(plot.getLastActivity() != null && plot.getLastActivity().getTime() < (new Date().getTime() - millisIn14Days)) {
if(plot.getLastActivity() != null && plot.getLastActivity().getTime() < (new Date().getTime() - millisInDays)) {
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
try {
PlotHandler.abandonPlot(plot);
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/defaultConfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ sync-ftp-files:
enabled: false
sync-interval: 3600

# How many days of inactivity it will take before a claimed plot is automatically abandoned
inactivity-interval: 16

# Enable or disable the Group System, that allows users to invite other Builders as members of their plot,
# allowing them to build together.
# NOTE: Score will be split by all participating members
enable-group-support: true

# -----------------------------------------------------
# | Supported databases: MariaDB and MySQL
Expand Down Expand Up @@ -86,4 +93,4 @@ error-colour: §c


# NOTE: Do not change
config-version: 1.2
config-version: 1.3

0 comments on commit 8c7a7ee

Please sign in to comment.