Dateien nach "MAIN/src/main/java/com/trafalcraft/anti_redstone_clock/object" hochladen
This commit is contained in:
@@ -0,0 +1,53 @@
|
|||||||
|
package com.trafalcraft.anti_redstone_clock.object;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import com.trafalcraft.anti_redstone_clock.Main;
|
||||||
|
|
||||||
|
public class RedstoneClock {
|
||||||
|
|
||||||
|
private final long endTime;
|
||||||
|
private int numberOfClock;
|
||||||
|
private final Location loc;
|
||||||
|
private int value;
|
||||||
|
private boolean detected;
|
||||||
|
|
||||||
|
public RedstoneClock(Location loc) {
|
||||||
|
endTime = System.currentTimeMillis() / 1000 + Main.getInstance().getConfig().getInt("Delay");
|
||||||
|
numberOfClock = 0;
|
||||||
|
this.loc = loc;
|
||||||
|
detected = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOneToClock() {
|
||||||
|
numberOfClock++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumberOfClock() {
|
||||||
|
return numberOfClock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateStatus(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastStatus() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTimedOut() {
|
||||||
|
return (System.currentTimeMillis() / 1000) >= endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDetected(boolean detected) {
|
||||||
|
this.detected = detected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDetected() {
|
||||||
|
return detected;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
package com.trafalcraft.anti_redstone_clock.object;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.trafalcraft.anti_redstone_clock.exception.DuplicateRedstoneClockObjectException;
|
||||||
|
import com.trafalcraft.anti_redstone_clock.util.Msg;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
public class RedstoneClockController {
|
||||||
|
private RedstoneClockController() {}
|
||||||
|
|
||||||
|
private static final ConcurrentMap<Location, RedstoneClock> activeMap = Maps.newConcurrentMap();
|
||||||
|
|
||||||
|
public static void addRedstone(Location location) throws DuplicateRedstoneClockObjectException {
|
||||||
|
if (contains(location)) {
|
||||||
|
throw new DuplicateRedstoneClockObjectException(Msg.ERROR + Msg.DUPLICATE_OBJECT.toString() + " " + location);
|
||||||
|
} else {
|
||||||
|
activeMap.put(location, new RedstoneClock(location));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean contains(Location location) {
|
||||||
|
return activeMap.containsKey(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeRedstoneByLocation(Location location) {
|
||||||
|
activeMap.remove(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removeRedstoneByObject(RedstoneClock rc) {
|
||||||
|
if (activeMap.containsValue(rc)) {
|
||||||
|
activeMap.remove(rc.getLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RedstoneClock getRedstoneClock(Location location) {
|
||||||
|
return activeMap.get(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Location, RedstoneClock> getHashMap() {
|
||||||
|
return activeMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<RedstoneClock> getAll() {
|
||||||
|
return activeMap.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<Location> getAllLoc() {
|
||||||
|
return activeMap.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user