/* * Copyright (c) IntellectualCrafters - 2014. * You are not allowed to distribute and/or monetize any of our intellectual property. * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. * * >> File = PlayerFunctions.java * >> Generated by: Citymonstret at 2014-08-09 01:43 */ package com.intellectualcrafters.plot; import org.bukkit.*; import org.bukkit.block.Biome; import org.bukkit.entity.Player; import java.util.*; /** * Functions involving players, plots and locations. * @author Citymonstret * */ @SuppressWarnings("javadoc") public class PlayerFunctions { /** * * @param player player * @return */ public static boolean isInPlot(Player player) { return getCurrentPlot(player) != null; } /** * * @param plot plot * @return */ public static boolean hasExpired(Plot plot) { OfflinePlayer player = Bukkit.getOfflinePlayer(plot.owner); long lp = player.getLastPlayed(); long cu = System.currentTimeMillis(); return (lp - cu) > 30l; } /** * * @param loc * @return */ public static PlotId getPlot(Location loc) { int valx = loc.getBlockX(); int valz = loc.getBlockZ(); PlotWorld plotworld = PlotMain.getWorldSettings(loc.getWorld()); int size = plotworld.PLOT_WIDTH + plotworld.ROAD_WIDTH; int pathsize = plotworld.ROAD_WIDTH; boolean road = false; double n3; int mod2 = 0; int mod1 = 1; int x = (int) Math.ceil((double) valx / size); int z = (int) Math.ceil((double) valz / size); if(pathsize % 2 == 1) { n3 = Math.ceil(((double) pathsize) / 2); mod2 = -1; } else { n3 = Math.floor(((double) pathsize) / 2); } for(double i = n3; i >= 0; i--) { if((valx - i + mod1) % size == 0 || (valx + i + mod2) % size == 0) { road = true; x = (int) Math.ceil((valx - n3) / size); } if((valz - i + mod1) % size == 0 || (valz + i + mod2) % size == 0) { road = true; z = (int) Math.ceil((valz - n3) / size); } } if(road) { return null; } else { return new PlotId(x,z); } } /** * * @param player * @param plot */ public static void togglePlotWeather(Player player, Plot plot) { player.setPlayerWeather(plot.settings.getRain() ? WeatherType.DOWNFALL : WeatherType.CLEAR); } /** * * @param player * @param plot */ public static void togglePlotTime(Player player, Plot plot) { player.setPlayerTime(plot.settings.getTime(), false); } /** * * @param player * @return */ @SuppressWarnings("deprecation") public static Plot getCurrentPlot(Player player) { if (!PlotMain.isPlotWorld(player.getWorld())) return null; PlotId id = getPlot(player.getLocation()); World world = player.getWorld(); if(id==null) { return null; } HashMap plots = PlotMain.getPlots(world); if (plots!=null) { if(plots.containsKey(id)) { return plots.get(id); } } else { } return new Plot(id, null, Biome.FOREST, new ArrayList(), new ArrayList(), world.getName()); } /** * @deprecated * @param id * @param plot */ public static void set(Integer[] id, Plot plot) { PlotMain.updatePlot(plot); } /** * * @param plr * @return */ // public static Set getPlayerPlots(Player plr) { // return PlotMain.getPlots(plr); // } // public static Set getPlayerPlots(World world, Player plr) { Set p = PlotMain.getPlots(world, plr); if (p==null) return new HashSet(); return p; } /** * * @param plr * @return */ // public static int getPlayerPlotCount(Player plr) { // return getPlayerPlots(plr).size(); // } // public static int getPlayerPlotCount(World world, Player plr) { return getPlayerPlots(world, plr).size(); } /** * * @param p * @return */ @SuppressWarnings("SuspiciousNameCombination") public static int getAllowedPlots(Player p) { if(p.hasPermission("plots.admin")) return Integer.MAX_VALUE; int y = 0; for(int x = 1; x <= 100; x++) { if(p.hasPermission("plots.plot." + x)) y = x; else { break; } } return y; } /** * * @return PlotMain.getPlots(); * @deprecated */ public static Set getPlots() { return PlotMain.getPlots(); } /** * \\previous\\ * @param plr * @param msg * Was used to wrap the chat client length (Packets out--) */ public static void sendMessageWrapped(Player plr, String msg) { plr.sendMessage(msg); } /** * Send a message to the player * @param plr Player to recieve message * @param msg Message to send */ public static void sendMessage(Player plr, String msg) { if(msg.length() == 0 || msg.equalsIgnoreCase("")) return; sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg)); } /** * Send a message to the player * @param plr Player to recieve message * @param c Caption to send */ public static void sendMessage(Player plr, C c, String ... args) { if(c.s().length() < 1) return; String msg = c.s(); if(args != null && args.length > 0) { for(String str : args) msg = msg.replaceFirst("%s", str); } sendMessage(plr, msg); } }