2016-01-15 18:06:34 +00:00
|
|
|
/*
|
|
|
|
|
GriefPrevention Server Plugin for Minecraft
|
|
|
|
|
Copyright (C) 2012 Ryan Hamshire
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-03-03 01:04:15 +00:00
|
|
|
package me.ryanhamshire.GriefPrevention;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
2018-09-22 12:21:00 +00:00
|
|
|
import java.util.Iterator;
|
2020-03-03 01:04:15 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
2018-09-22 12:21:00 +00:00
|
|
|
import java.util.UUID;
|
2020-03-03 01:04:15 +00:00
|
|
|
import java.util.stream.Collectors;
|
2016-01-15 18:06:34 +00:00
|
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
|
|
|
|
|
//FEATURE: automatically remove claims owned by inactive players which:
|
|
|
|
|
//...aren't protecting much OR
|
|
|
|
|
//...are a free new player claim (and the player has no other claims) OR
|
|
|
|
|
//...because the player has been gone a REALLY long time, and that expiration has been configured in config.yml
|
|
|
|
|
|
|
|
|
|
//runs every 1 minute in the main thread
|
|
|
|
|
class FindUnusedClaimsTask implements Runnable
|
2018-09-22 12:21:00 +00:00
|
|
|
{
|
2020-03-03 01:04:15 +00:00
|
|
|
private List<UUID> claimOwnerUUIDs;
|
2018-09-22 12:21:00 +00:00
|
|
|
private Iterator<UUID> claimOwnerIterator;
|
2016-01-15 18:06:34 +00:00
|
|
|
|
|
|
|
|
FindUnusedClaimsTask()
|
|
|
|
|
{
|
2018-09-22 12:21:00 +00:00
|
|
|
refreshUUIDs();
|
2016-01-15 18:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run()
|
|
|
|
|
{
|
|
|
|
|
//don't do anything when there are no claims
|
2018-09-22 12:21:00 +00:00
|
|
|
if(claimOwnerUUIDs.isEmpty()) return;
|
2016-01-15 18:06:34 +00:00
|
|
|
|
|
|
|
|
//wrap search around to beginning
|
2018-09-22 12:21:00 +00:00
|
|
|
if(!claimOwnerIterator.hasNext())
|
|
|
|
|
{
|
|
|
|
|
refreshUUIDs();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-01-15 18:06:34 +00:00
|
|
|
|
2018-09-22 12:21:00 +00:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(GriefPrevention.instance, new CleanupUnusedClaimPreTask(claimOwnerIterator.next()));
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 01:04:15 +00:00
|
|
|
public void refreshUUIDs() {
|
|
|
|
|
// Fetch owner UUIDs from list of claims
|
2020-03-13 00:53:29 +00:00
|
|
|
claimOwnerUUIDs = GriefPrevention.instance.dataStore.claims.stream().map(claim -> claim.ownerID)
|
|
|
|
|
.distinct().filter(Objects::nonNull).collect(Collectors.toList());
|
2020-03-03 01:04:15 +00:00
|
|
|
|
|
|
|
|
if (!claimOwnerUUIDs.isEmpty()) {
|
|
|
|
|
// Randomize order
|
|
|
|
|
Collections.shuffle(claimOwnerUUIDs);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-22 12:21:00 +00:00
|
|
|
claimOwnerIterator = claimOwnerUUIDs.iterator();
|
2016-01-15 18:06:34 +00:00
|
|
|
}
|
|
|
|
|
}
|