Created
March 4, 2015 05:15
-
-
Save phroa/d04d321b2d1e333ba8c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.phroa.pads.impl; | |
import com.flowpowered.math.vector.Vector3d; | |
import com.google.common.base.Optional; | |
import net.phroa.pads.api.Pad; | |
import net.phroa.pads.api.PadManager; | |
import org.spongepowered.api.world.Location; | |
import javax.annotation.Nonnull; | |
import java.util.Collection; | |
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.UUID; | |
public class TeleportPadManager implements PadManager { | |
private Set<Pad> pads; | |
public TeleportPadManager() { | |
this.pads = new HashSet<Pad>(); | |
} | |
@Override | |
public void register(@Nonnull Pad pad) { | |
pads.add(pad); | |
} | |
@Override | |
public boolean remove(@Nonnull UUID padID) { | |
for (Pad pad : pads) { | |
if (pad.getPadID() == padID) { | |
return pads.remove(pad); | |
} | |
} | |
return false; | |
} | |
@Override | |
public boolean remove(@Nonnull Pad pad) { | |
return pads.remove(pad); | |
} | |
@Override | |
public boolean exists(@Nonnull UUID padID) { | |
for (Pad pad : pads) { | |
if (pad.getPadID() == padID) { | |
return true; | |
} | |
} | |
return false; | |
} | |
@Override | |
public boolean exists(@Nonnull Pad pad) { | |
return pads.contains(pad); | |
} | |
@Override | |
public Optional<Pad> isLocationInsidePad(@Nonnull Location location) { | |
for (Pad pad : pads) { | |
if (!pad.getMin().isPresent() || !pad.getMax().isPresent()) continue; | |
Vector3d min = pad.getMin().get().getPosition(); | |
Vector3d max = pad.getMax().get().getPosition(); | |
Vector3d position = location.getPosition(); | |
if (min.compareTo(position) <= 0 && position.compareTo(max) <= 0) { | |
return Optional.of(pad); | |
} | |
} | |
return Optional.absent(); | |
} | |
@Override | |
public Optional<Pad> getPad(@Nonnull UUID padID) { | |
for (Pad pad : pads) { | |
if (pad.getPadID() == padID) { | |
return Optional.of(pad); | |
} | |
} | |
return Optional.absent(); | |
} | |
@Override | |
public Collection<Pad> getPads() { | |
return pads; | |
} | |
@Override | |
public int size() { | |
return pads.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment