73 lines
1.8 KiB
Java
73 lines
1.8 KiB
Java
package nl.iobyte.themepark.api.ridecount;
|
|
|
|
import nl.iobyte.themepark.api.API;
|
|
import nl.iobyte.themepark.api.attraction.Attraction;
|
|
import java.util.HashMap;
|
|
import java.util.UUID;
|
|
|
|
public class CountManager {
|
|
|
|
private static HashMap<String, AttractionCount> counts = new HashMap<>();
|
|
|
|
public static void addCounter(Attraction attraction) {
|
|
if(attraction == null)
|
|
return;
|
|
|
|
if(counts.containsKey(attraction.getId()))
|
|
return;
|
|
|
|
if(!API.isAttraction(attraction.getId()))
|
|
return;
|
|
|
|
counts.put(attraction.getId(), new AttractionCount(attraction));
|
|
}
|
|
|
|
public static boolean isCounter(String id) {
|
|
if(id == null || id.isEmpty())
|
|
return false;
|
|
|
|
return counts.containsKey(id);
|
|
}
|
|
|
|
public static AttractionCount getCounter(String id) {
|
|
if(!isCounter(id))
|
|
return null;
|
|
|
|
return counts.get(id);
|
|
}
|
|
|
|
public static void removeCounter(String id) {
|
|
if(!isCounter(id))
|
|
return;
|
|
|
|
counts.remove(id);
|
|
}
|
|
|
|
public static void addCount(Attraction attraction, UUID uuid, int amount) {
|
|
if(attraction == null)
|
|
return;
|
|
|
|
AttractionCount count = getCounter(attraction.getId());
|
|
if(count == null)
|
|
return;
|
|
|
|
count.addCount(uuid, amount);
|
|
}
|
|
|
|
public static void setCount(Attraction attraction, UUID uuid, int amount) {
|
|
if(attraction == null)
|
|
return;
|
|
|
|
AttractionCount count = getCounter(attraction.getId());
|
|
if(count == null)
|
|
return;
|
|
|
|
count.setCount(uuid, amount);
|
|
}
|
|
|
|
public static void removeCount(UUID uuid) {
|
|
for(AttractionCount attractionCount : counts.values())
|
|
attractionCount.removeCount(uuid);
|
|
}
|
|
|
|
}
|