mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 11:15:47 +01:00
Use multimap in scheduler
This commit is contained in:
parent
b91564f77a
commit
779582d441
@ -1,6 +1,10 @@
|
|||||||
package net.md_5.bungee.scheduler;
|
package net.md_5.bungee.scheduler;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.common.collect.ArrayListMultimap;
|
||||||
|
import com.google.common.collect.HashMultimap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
|
import com.google.common.collect.Multimaps;
|
||||||
import gnu.trove.TCollections;
|
import gnu.trove.TCollections;
|
||||||
import gnu.trove.map.TIntObjectMap;
|
import gnu.trove.map.TIntObjectMap;
|
||||||
import gnu.trove.map.hash.TIntObjectHashMap;
|
import gnu.trove.map.hash.TIntObjectHashMap;
|
||||||
@ -18,11 +22,13 @@ public class BungeeScheduler implements TaskScheduler
|
|||||||
|
|
||||||
private final AtomicInteger taskCounter = new AtomicInteger();
|
private final AtomicInteger taskCounter = new AtomicInteger();
|
||||||
private final TIntObjectMap<BungeeTask> tasks = TCollections.synchronizedMap( new TIntObjectHashMap<BungeeTask>() );
|
private final TIntObjectMap<BungeeTask> tasks = TCollections.synchronizedMap( new TIntObjectHashMap<BungeeTask>() );
|
||||||
|
private final Multimap<Plugin, BungeeTask> tasksByPlugin = Multimaps.synchronizedMultimap( HashMultimap.<Plugin, BungeeTask>create() );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel(int id)
|
public void cancel(int id)
|
||||||
{
|
{
|
||||||
BungeeTask task = tasks.remove( id );
|
BungeeTask task = tasks.remove( id );
|
||||||
|
tasksByPlugin.values().remove( task );
|
||||||
task.getFuture().cancel( false );
|
task.getFuture().cancel( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,14 +42,10 @@ public class BungeeScheduler implements TaskScheduler
|
|||||||
public int cancel(Plugin plugin)
|
public int cancel(Plugin plugin)
|
||||||
{
|
{
|
||||||
Set<ScheduledTask> toRemove = new HashSet<>();
|
Set<ScheduledTask> toRemove = new HashSet<>();
|
||||||
for ( ScheduledTask task : tasks.valueCollection() )
|
for ( ScheduledTask task : tasksByPlugin.get( plugin ) )
|
||||||
{
|
|
||||||
// TODO: proper checking?
|
|
||||||
if ( task.getOwner() == plugin )
|
|
||||||
{
|
{
|
||||||
toRemove.add( task );
|
toRemove.add( task );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for ( ScheduledTask task : toRemove )
|
for ( ScheduledTask task : toRemove )
|
||||||
{
|
{
|
||||||
cancel( task );
|
cancel( task );
|
||||||
|
Loading…
Reference in New Issue
Block a user