Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.plaria.system.utils.manager;
- import com.google.common.collect.Lists;
- import de.dytanic.cloudnet.common.collection.Maps;
- import net.plaria.system.SystemPlugin;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import java.util.List;
- import java.util.Map;
- public class WarpManager {
- private final SystemPlugin systemPlugin;
- private final Map<String, Location> warps;
- private final Map<String, Integer> warpProtection;
- /**
- *
- * @param systemPlugin
- */
- public WarpManager(final SystemPlugin systemPlugin) {
- this.systemPlugin = systemPlugin;
- this.warps = Maps.newConcurrentHashMap();
- this.warpProtection = Maps.newConcurrentHashMap();
- loadWarps();
- }
- /**
- * Warps:
- * - NAME;WORLD;X;Y;Z;Yaw;Pitch;Protection-Radius
- *
- * Example:
- * - Qetz;world;0;100;0;0;010
- */
- private void loadWarps() {
- Bukkit.getScheduler().runTaskLaterAsynchronously(this.systemPlugin, () -> {
- for(String warp : this.systemPlugin.getConfigFileHandler().getCfg().getStringList("Warps")) {
- String warpName = warp.split(";")[0].toUpperCase();
- World world = Bukkit.getWorld(warp.split(";")[1]);
- double x = Double.parseDouble(warp.split(";")[2]);
- double y = Double.parseDouble(warp.split(";")[3]);
- double z = Double.parseDouble(warp.split(";")[4]);
- float yaw = Float.parseFloat(warp.split(";")[5]);
- float pitch = Float.parseFloat(warp.split(";")[6]);
- int protection = Integer.parseInt(warp.split(";")[7]);
- addWarp(warpName, new Location(world, x, y, z, yaw, pitch), protection);
- }
- }, 20 * 3);
- }
- public void saveWarps() {
- List<String> warps = Lists.newArrayList();
- for(String warpName : this.warps.keySet()) {
- Location warpLocation = this.warps.get(warpName.toUpperCase());
- int protection = this.warpProtection.get(warpName.toUpperCase());
- warps.add(warpName + ";" + warpLocation.getWorld() + ";" + warpLocation.getX() + ";" + warpLocation.getY() +
- ";" + warpLocation.getZ() + warpLocation.getYaw() + warpLocation.getPitch() + ";" + protection);
- }
- this.systemPlugin.getConfigFileHandler().getCfg().set("Warps", warps);
- this.systemPlugin.getConfigFileHandler().save();
- }
- public boolean existWarp(String warpName) {
- return this.warps.containsKey(warpName.toUpperCase());
- }
- public boolean addWarp(String warpName, Location warpLocation, int protection) {
- if (!existWarp(warpName.toUpperCase())) {
- this.warps.put(warpName.toUpperCase(), warpLocation);
- this.warpProtection.put(warpName.toUpperCase(), protection);
- return true;
- }
- return false;
- }
- public boolean addWarp(String warpName, Location warpLocation) {
- return addWarp(warpName, warpLocation, 0);
- }
- public boolean removeWarp(String warpName) {
- if(existWarp(warpName.toUpperCase())) {
- this.warps.remove(warpName.toUpperCase());
- this.warpProtection.remove(warpName.toUpperCase());
- return true;
- }
- return false;
- }
- public Location getLocation(String warpName) {
- return this.warps.get(warpName.toUpperCase());
- }
- public int getProtection(String warpName) {
- return this.warpProtection.get(warpName.toUpperCase());
- }
- public String[] getNames() {
- return this.warps.keySet().toArray(new String[warps.keySet().size()]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement