SHARE
TWEET

Untitled

Lisenochek Oct 22nd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ru.lisenochek.mcrust.objects.misc;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.entity.Player;
  5. import ru.lisenochek.mcrust.sql.SQLManager;
  6. import ru.lisenochek.mcrust.utils.Cuboid;
  7.  
  8. import java.util.HashMap;
  9.  
  10. public class Radtown {
  11.  
  12.     private static HashMap<String, Radtown> radtownsMap = new HashMap<>();
  13.     private static HashMap<Location, Radtown> locationsMap = new HashMap<>();
  14.  
  15.     private String name;
  16.     private Cuboid cuboid;
  17.     private Radiation radiation;
  18.  
  19.     private Radtown(String name, Radiation radiation, Cuboid cuboid) {
  20.         this.name = name;
  21.         this.cuboid = cuboid;
  22.         this.radiation = radiation;
  23.         for (Location loc : cuboid.getBlocksList()) locationsMap.put(loc, this);
  24.         radtownsMap.put(name, this);
  25.     }
  26.  
  27.     public static Radtown create(String name, Radiation radiation, Cuboid cuboid) {
  28.         return new Radtown(name, radiation, cuboid);
  29.     }
  30.  
  31.     public static Radtown fromName(String name) {
  32.         return radtownsMap.get(name);
  33.     }
  34.  
  35.     public static Radtown fromLocation(Location location) {
  36.         return locationsMap.get(location);
  37.     }
  38.  
  39.     public static boolean checkBreak(Player player, Location location) {
  40.         if (locationsMap.get(location) == null) return true;
  41.         return player.hasPermission("mcrust.admin") || CustomBlock.getBlock(location.getBlock()).getType().isIgnoreBreakCupboard();
  42.     }
  43.  
  44.     public static boolean checkPlace(Player player, Location location) {
  45.         if (locationsMap.get(location) == null) return true;
  46.         return player.hasPermission("mcrust.admin") || CustomBlock.getBlock(location.getBlock()).getType().isIgnoreBuildCupboard();
  47.     }
  48.  
  49.     public String getName() {
  50.         return name;
  51.     }
  52.  
  53.     public Cuboid getCuboid() {
  54.         return cuboid;
  55.     }
  56.  
  57.     public Radiation getRadiation() {
  58.         return radiation;
  59.     }
  60.  
  61.     public void remove() {
  62.         for (Location location : cuboid.getBlocksList()) locationsMap.remove(location);
  63.         radtownsMap.remove(name);
  64.         SQLManager.getManager().deleteRadtownData(this);
  65.     }
  66.  
  67.     public enum Radiation {
  68.  
  69.         NONE(0, 0, 0),
  70.         LOW(10, 60, 35),
  71.         MEDIUM(45, 25, 50),
  72.         HARD(75, 15, 80);
  73.  
  74.         private int minimumProtection;
  75.         private int triggerTime;
  76.         private int chance;
  77.  
  78.         Radiation(int minimumProtection, int triggerTime, int chance) {
  79.             this.minimumProtection = minimumProtection;
  80.             this.triggerTime = triggerTime;
  81.             this.chance = chance;
  82.         }
  83.  
  84.         public int getMinimumProtection() {
  85.             return minimumProtection;
  86.         }
  87.  
  88.         public int getTriggerTime() {
  89.             return triggerTime;
  90.         }
  91.  
  92.         public int getChance() {
  93.             return chance;
  94.         }
  95.     }
  96. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top