SHARE
TWEET

Untitled

a guest Nov 21st, 2019 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.insideintel;
  2.  
  3. import org.bukkit.plugin.java.JavaPlugin;
  4.  
  5. import me.clip.placeholderapi.PlaceholderAPI;
  6. import me.clip.placeholderapi.expansion.Configurable;
  7. import me.clip.placeholderapi.expansion.PlaceholderExpansion;
  8. import me.ryanhamshire.GriefPrevention.Claim;
  9. import me.ryanhamshire.GriefPrevention.DataStore;
  10. import me.ryanhamshire.GriefPrevention.GriefPrevention;
  11. import me.ryanhamshire.GriefPrevention.PlayerData;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.ChatColor;
  14. import org.bukkit.entity.Player;
  15.  
  16. import java.text.NumberFormat;
  17. import java.util.HashMap;
  18. import java.util.Locale;
  19. import java.util.Map;
  20.  
  21. public class gpexpansion extends PlaceholderExpansion implements Configurable {
  22.  
  23.     private GriefPrevention plugin;
  24.  
  25.     /**
  26.      * Since this expansion requires api access to the plugin "SomePlugin" we must
  27.      * check if "SomePlugin" is on the server in this method
  28.      */
  29.     @Override
  30.     public boolean canRegister() {
  31.         return Bukkit.getPluginManager().getPlugin(getPlugin()) != null;
  32.     }
  33.  
  34.     /**
  35.      * We can optionally override this method if we need to initialize variables
  36.      * within this class if we need to or even if we have to do other checks to
  37.      * ensure the hook is properly setup.
  38.      */
  39.     @Override
  40.     public boolean register() {
  41.         /*
  42.          * Make sure "SomePlugin" is on the server
  43.          */
  44.         if (!canRegister()) {
  45.             return false;
  46.         }
  47.  
  48.         /*
  49.          * "SomePlugin" does not have static methods to access its api so we must create
  50.          * set a variable to obtain access to it
  51.          */
  52.         plugin = (GriefPrevention) Bukkit.getPluginManager().getPlugin(getPlugin());
  53.  
  54.         /*
  55.          * if for some reason we can not get our variable, we should return false
  56.          */
  57.         if (plugin == null) {
  58.             return false;
  59.         }
  60.         /*
  61.          * Since we override the register method, we need to manually register this hook
  62.          */
  63.         return PlaceholderAPI.registerPlaceholderHook(getIdentifier(), this);
  64.     }
  65.  
  66.     /**
  67.      * The name of the person who created this expansion should go here
  68.      */
  69.     @Override
  70.     public String getAuthor() {
  71.         return "pixar02";
  72.     }
  73.  
  74.     /**
  75.      * The placeholder identifier should go here This is what tells PlaceholderAPI
  76.      * to call our onPlaceholderRequest method to obtain a value if a placeholder
  77.      * starts with our identifier. This must be unique and can not contain % or _
  78.      */
  79.     @Override
  80.     public String getIdentifier() {
  81.         return "griefprevention";
  82.     }
  83.  
  84.     /**
  85.      * if an expansion requires another plugin as a dependency, the proper name of
  86.      * the dependency should go here. Set this to null if your placeholders do not
  87.      * require another plugin be installed on the server for them to work. This is
  88.      * extremely important to set if you do have a dependency because if your
  89.      * dependency is not loaded when this hook is registered, it will be added to a
  90.      * cache to be registered when plugin: "getPlugin()" is enabled on the server.
  91.      */
  92.     @Override
  93.     public String getPlugin() {
  94.         return "GriefPrevention";
  95.     }
  96.  
  97.     /**
  98.      * This is the version of this expansion
  99.      */
  100.     @Override
  101.     public String getVersion() {
  102.         return "1.4.1";
  103.     }
  104.  
  105.     @Override
  106.     public Map<String, Object> getDefaults() {
  107.         Map<String, Object> defaults = new HashMap<String, Object>();
  108.         defaults.put("formatting.thousands", "k");
  109.         defaults.put("formatting.millions", "M");
  110.         defaults.put("formatting.billions", "B");
  111.         defaults.put("formatting.trillions", "T");
  112.         defaults.put("formatting.quadrillions", "Q");
  113.         defaults.put("color.enemy", "&4");
  114.         defaults.put("color.trusted", "&a");
  115.         defaults.put("color.neutral", "&7");
  116.         return defaults;
  117.     }
  118.  
  119.     /**
  120.      * This is the method called when a placeholder with our identifier is found and
  121.      * needs a value We specify the value identifier in this method
  122.      */
  123.     @Override
  124.     public String onPlaceholderRequest(Player p, String identifier) {
  125.  
  126.         if (p == null) {
  127.             return "";
  128.         }
  129.  
  130.         DataStore DataS = plugin.dataStore;
  131.         PlayerData pd = DataS.getPlayerData(p.getUniqueId());
  132.         if (identifier.equals("getplayerclaimblocks")) {
  133.             return String.valueOf(pd.getClaims()); // Nick, this
  134.         }
  135.         /*
  136.          %griefprevention_claims%
  137.          %griefprevention_claims_formatted%
  138.         */
  139.         if (identifier.equals("claims")) {
  140.             return String.valueOf(pd.getClaims().size());
  141.         } else if (identifier.equals("claims_formatted")) {
  142.             return fixMoney(pd.getClaims().size());
  143.         }
  144.  
  145.         // %griefprevention_bonusclaims%
  146.         if (identifier.equals("bonusclaims")) {
  147.             return String.valueOf(pd.getBonusClaimBlocks());
  148.         }
  149.  
  150.         /*
  151.          %griefprevention_accruedclaims%
  152.          %griefprevention_accruedclaims_formatted%
  153.         */
  154.         if (identifier.equals("accruedclaims")) {
  155.             return String.valueOf(pd.getAccruedClaimBlocks());
  156.         } else if (identifier.equals("accruedclaims_formatted")) {
  157.             return fixMoney(pd.getAccruedClaimBlocks());
  158.         }
  159.  
  160.         // %griefprevention_accruedclaims_limit%
  161.         if (identifier.equals("accruedclaims_limit")) {
  162.             return String.valueOf(pd.getAccruedClaimBlocksLimit());
  163.         }
  164.  
  165.         /*
  166.          %griefprevention_remainingclaims%
  167.          %griefprevention_remainingclaims_formatted%
  168.         */
  169.         if (identifier.equals("remainingclaims")) {
  170.             return String.valueOf(pd.getRemainingClaimBlocks());
  171.         } else if (identifier.equals("remainingclaims_formatted")) {
  172.             return fixMoney(pd.getRemainingClaimBlocks());
  173.         }
  174.  
  175.         // %griefprevention_currentclaim_ownername_color%
  176.         // %griefprevention_currentclaim_ownername%
  177.         if (identifier.equals("currentclaim_ownername")) {
  178.             Claim claim = DataS.getClaimAt(p.getLocation(), true, null);
  179.             if (claim == null) {
  180.                 return "Unclaimed";
  181.             } else {
  182.                 return String.valueOf(claim.getOwnerName());
  183.             }
  184.         } else if (identifier.equals("currentclaim_ownername_color")) {
  185.             Claim claim = DataS.getClaimAt(p.getLocation(), true, null);
  186.             if (claim == null) {
  187.                 return ChatColor.translateAlternateColorCodes('&',
  188.                         getString("color.neutral", "") + "Unclaimed");
  189.             } else {
  190.                 if (claim.allowAccess(p) == null){
  191.                     //Trusted
  192.                     return ChatColor.translateAlternateColorCodes('&',
  193.                             getString("color.trusted", "") + String.valueOf(claim.getOwnerName()));
  194.                 }else{
  195.                     // not trusted
  196.                     return ChatColor.translateAlternateColorCodes('&',
  197.                             getString("color.enemy", "") + String.valueOf(claim.getOwnerName()));
  198.  
  199.                 }
  200.             }
  201.         }
  202.         return null;
  203.     }
  204.  
  205.     private String fixMoney(double d) {
  206.         if (d < 1000L) {
  207.             return format(d);
  208.         }
  209.         if (d < 1000000L) {
  210.             return format(d / 1000L) + getString("formatting.thousands", "k");
  211.         }
  212.         if (d < 1000000000L) {
  213.             return format(d / 1000000L) + getString("formatting.millions", "m");
  214.         }
  215.         if (d < 1000000000000L) {
  216.             return format(d / 1000000000L) + getString("formatting.billions", "b");
  217.         }
  218.         if (d < 1000000000000000L) {
  219.             return format(d / 1000000000000L) + getString("formatting.trillions", "t");
  220.         }
  221.         if (d < 1000000000000000000L) {
  222.             return format(d / 1000000000000000L) + getString("formatting.quadrillions", "q");
  223.         }
  224.         return toLong(d);
  225.     }
  226.  
  227.     private String toLong(double amt) {
  228.         long send = (long) amt;
  229.         return String.valueOf(send);
  230.     }
  231.  
  232.     private String format(double d) {
  233.         NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
  234.         format.setMaximumFractionDigits(2);
  235.         format.setMinimumFractionDigits(0);
  236.         return format.format(d);
  237.     }
  238.  
  239. }
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