From 2ec5f2673796b9b48c338844f32cd703283fe3dd Mon Sep 17 00:00:00 2001 From: alisolarflare Date: Wed, 30 Nov 2016 00:33:10 -0500 Subject: [PATCH] Created CreativeBoundariesAPI --- .../CreativeBoundariesAPI.java | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/alisolarflare/components/creativeboundaries/CreativeBoundariesAPI.java diff --git a/src/alisolarflare/components/creativeboundaries/CreativeBoundariesAPI.java b/src/alisolarflare/components/creativeboundaries/CreativeBoundariesAPI.java new file mode 100644 index 0000000..77b7996 --- /dev/null +++ b/src/alisolarflare/components/creativeboundaries/CreativeBoundariesAPI.java @@ -0,0 +1,84 @@ +package alisolarflare.components.creativeboundaries; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownBlock; +import com.palmergames.bukkit.towny.object.TownyUniverse; + +public class CreativeBoundariesAPI { + private static List cbCreatives = new ArrayList(); + private static boolean forceBoundaries = false; + public CreativeBoundariesAPI(List cbCreatives){ + CreativeBoundariesAPI.cbCreatives = cbCreatives; + } + public static void toSurvival(Player player){ + player.setGameMode(GameMode.SURVIVAL); + cbCreatives.remove(player); + } + public static boolean toCreative(Player player){ + TownBlock tb = TownyUniverse.getTownBlock(player.getLocation()); + + if (tb == null) { + player.sendMessage("Some error occured."); + player.sendMessage("TownBlock is null."); + return false; + } + Town town; + try { + town = tb.getTown(); + } catch (NotRegisteredException e) { + player.sendMessage("You aren't standing in a town, head to your home town to use this command."); + return false; + } + + boolean playerIsInTown = false; + for(Resident res : town.getResidents()){ + if (res.getName().toString().equals(player.getName().toString())){ + playerIsInTown = true; + break; + } + } + if (!playerIsInTown){ + player.sendMessage("Sorry, you're not part of this town"); + return false; + } + + player.setGameMode(GameMode.CREATIVE); + cbCreatives.add(player); + return true; + } + public static void setForceBoundaries(boolean forceBoundaries){ + CreativeBoundariesAPI.forceBoundaries = forceBoundaries; + } + public static boolean setForceBoundaries(Player player, String[] args){ + if(args.length < 1){ + player.sendMessage("You must use True, False, 1, or 0 as arguments!"); + return false; + } + String firstArgument = args[0]; + if(firstArgument.startsWith("t") || firstArgument.equals("1")){ + player.sendMessage("Dickmode has been turned on!"); + forceBoundaries = true; + return true; + } + if(firstArgument.startsWith("f") || firstArgument.equals("0")){ + player.sendMessage("Dickmode has been turned off!"); + forceBoundaries = false; + return true; + } + return false; + } + public static boolean getforceBoundaries(){ + return forceBoundaries; + } + public static boolean isCBCreative(Player player){ + return cbCreatives.contains(player); + } +}