├── src ├── com │ └── palmergames │ │ ├── bukkit │ │ ├── util │ │ │ ├── ChatTools.java │ │ │ ├── ServerBroadCastTimerTask.java │ │ │ ├── ArraySort.java │ │ │ ├── Colors.java │ │ │ ├── Compass.java │ │ │ ├── TimeTools.java │ │ │ └── MinecraftTools.java │ │ ├── towny │ │ │ ├── command │ │ │ │ └── TownyCommand.java │ │ │ ├── object │ │ │ │ ├── ResidentList.java │ │ │ │ ├── blockObject.java │ │ │ │ ├── NeedsPlaceholder.java │ │ │ │ ├── TownyObservableType.java │ │ │ │ ├── BlockLocation.java │ │ │ │ ├── TownyObject.java │ │ │ │ ├── WorldCoord.java │ │ │ │ ├── TownBlockOwner.java │ │ │ │ ├── TownSpawnLevel.java │ │ │ │ ├── Coord.java │ │ │ │ ├── TownBlockType.java │ │ │ │ ├── TownyRegenAPI.java │ │ │ │ ├── Resident.java │ │ │ │ ├── TownBlock.java │ │ │ │ └── PlotBlockData.java │ │ │ ├── war │ │ │ │ ├── WarSpoils.java │ │ │ │ ├── StartWarTimerTask.java │ │ │ │ └── WarTimerTask.java │ │ │ ├── NotRegisteredException.java │ │ │ ├── AlreadyRegisteredException.java │ │ │ ├── Election.java │ │ │ ├── TownyException.java │ │ │ ├── questioner │ │ │ │ ├── TownQuestionTask.java │ │ │ │ ├── ResidentQuestionTask.java │ │ │ │ ├── TownyQuestionTask.java │ │ │ │ ├── ResidentTownQuestionTask.java │ │ │ │ ├── ResidentNationQuestionTask.java │ │ │ │ ├── JoinTownTask.java │ │ │ │ └── JoinNationTask.java │ │ │ ├── EconomyException.java │ │ │ ├── EmptyNationException.java │ │ │ ├── tasks │ │ │ │ ├── TownyTimerTask.java │ │ │ │ ├── SetDefaultModes.java │ │ │ │ ├── RepeatingTimerTask.java │ │ │ │ ├── ResidentPurge.java │ │ │ │ ├── HealthRegenTimerTask.java │ │ │ │ ├── TeleportWarmupTimerTask.java │ │ │ │ ├── ProtectionRegenTask.java │ │ │ │ ├── MobRemovalTimerTask.java │ │ │ │ └── TownClaim.java │ │ │ ├── event │ │ │ │ ├── TownyWeatherListener.java │ │ │ │ └── TownyWorldListener.java │ │ │ ├── EmptyTownException.java │ │ │ ├── TownyLogFormatter.java │ │ │ ├── TownyMoneyLogFormatter.java │ │ │ ├── permissions │ │ │ │ ├── PermissionEventEnums.java │ │ │ │ ├── NullPermSource.java │ │ │ │ ├── BukkitPermSource.java │ │ │ │ ├── PermissionNodes.java │ │ │ │ ├── bPermsSource.java │ │ │ │ ├── Perms3Source.java │ │ │ │ ├── TownyPermissionSource.java │ │ │ │ ├── GroupManagerSource.java │ │ │ │ └── PEXSource.java │ │ │ ├── db │ │ │ │ └── TownySQLTown.java │ │ │ ├── TownyLogger.java │ │ │ ├── PlayerCache.java │ │ │ └── TownyAsciiMap.java │ │ ├── townywar │ │ │ ├── event │ │ │ │ ├── CellAttackCanceledEvent.java │ │ │ │ ├── CellWonEvent.java │ │ │ │ ├── CellDefendedEvent.java │ │ │ │ └── CellAttackEvent.java │ │ │ ├── listener │ │ │ │ ├── TownyWarEntityListener.java │ │ │ │ ├── TownyWarBlockListener.java │ │ │ │ └── TownyWarCustomListener.java │ │ │ ├── CellAttackThread.java │ │ │ ├── Cell.java │ │ │ ├── TownyWarConfig.java │ │ │ └── CellUnderAttack.java │ │ └── blockqueue │ │ │ ├── BlockJob.java │ │ │ ├── BlockWork.java │ │ │ ├── BlockQueue.java │ │ │ └── BlockWorker.java │ │ └── util │ │ ├── KeyValue.java │ │ ├── MemMgmt.java │ │ ├── JavaUtil.java │ │ ├── KeyValueTable.java │ │ ├── Sorting.java │ │ ├── TimeMgmt.java │ │ └── StringMgmt.java └── ToDo.txt └── .gitignore /src/com/palmergames/bukkit/util/ChatTools.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zren/Towny/HEAD/src/com/palmergames/bukkit/util/ChatTools.java -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/command/TownyCommand.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zren/Towny/HEAD/src/com/palmergames/bukkit/towny/command/TownyCommand.java -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/ResidentList.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.List; 4 | 5 | public interface ResidentList { 6 | public List getResidents(); 7 | public boolean hasResident(String name); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/palmergames/util/KeyValue.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | public class KeyValue { 4 | public K key; 5 | public V value; 6 | 7 | public KeyValue(K key, V value) { 8 | this.key = key; 9 | this.value = value; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/war/WarSpoils.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.war; 2 | 3 | import com.palmergames.bukkit.towny.object.TownyEconomyObject; 4 | 5 | public class WarSpoils extends TownyEconomyObject { 6 | public WarSpoils() { 7 | setName("towny-war-chest"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/NotRegisteredException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | 4 | public class NotRegisteredException extends TownyException { 5 | private static final long serialVersionUID = 175945283391669005L; 6 | 7 | public NotRegisteredException() { 8 | super("Not registered."); 9 | } 10 | 11 | public NotRegisteredException(String message) { 12 | super(message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/AlreadyRegisteredException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | public class AlreadyRegisteredException extends TownyException { 4 | private static final long serialVersionUID = 4191685552690886161L; 5 | 6 | public AlreadyRegisteredException() { 7 | super("Already registered."); 8 | } 9 | 10 | public AlreadyRegisteredException(String message) { 11 | super(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/Election.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | //import java.util.HashMap; 4 | 5 | public class Election { 6 | // private HashMap options; 7 | // private HashMap voters; 8 | 9 | private long endDate; 10 | 11 | public void setEndDate(long endDate) { 12 | this.endDate = endDate; 13 | } 14 | 15 | public long getEndDate() { 16 | return endDate; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/TownyException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | public class TownyException extends Exception { 4 | private static final long serialVersionUID = -6821768221748544277L; 5 | 6 | public TownyException() { 7 | super("unknown"); 8 | } 9 | 10 | public TownyException(String message) { 11 | super(message); 12 | } 13 | 14 | @Deprecated 15 | public String getError() { 16 | return getMessage(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /make_jar.jardesc 2 | /lib 3 | 4 | # Eclipse stuff 5 | /.classpath 6 | /.project 7 | /.settings 8 | *.jardesc 9 | 10 | # netbeans 11 | /nbproject 12 | 13 | # we use maven! 14 | /build.xml 15 | 16 | # maven 17 | /target 18 | 19 | # vim 20 | .*.sw[a-p] 21 | 22 | # various other potential build files 23 | /build 24 | /bin 25 | /dist 26 | /manifest.mf 27 | 28 | # Mac filesystem dust 29 | /.DS_Store 30 | 31 | # intellij 32 | *.iml 33 | *.ipr 34 | *.iws 35 | .idea/ -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/TownQuestionTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.object.Town; 4 | 5 | public class TownQuestionTask extends TownyQuestionTask { 6 | protected Town town; 7 | 8 | public TownQuestionTask(Town town) { 9 | this.town = town; 10 | } 11 | 12 | public Town getTown() { 13 | return town; 14 | } 15 | 16 | @Override 17 | public void run() { 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/war/StartWarTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.war; 2 | 3 | import com.palmergames.bukkit.towny.object.TownyUniverse; 4 | import com.palmergames.bukkit.towny.tasks.TownyTimerTask; 5 | 6 | public class StartWarTimerTask extends TownyTimerTask { 7 | 8 | public StartWarTimerTask(TownyUniverse universe) { 9 | super(universe); 10 | } 11 | 12 | @Override 13 | public void run() { 14 | universe.getWarEvent().start(); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/EconomyException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | public class EconomyException extends Exception { 4 | private static final long serialVersionUID = 5273714478509976170L; 5 | public String error; 6 | 7 | public EconomyException() { 8 | super(); 9 | error = "unknown"; 10 | } 11 | 12 | public EconomyException(String error) { 13 | super(error); 14 | this.error = error; 15 | } 16 | 17 | public String getError() { 18 | return error; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/ResidentQuestionTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.object.Resident; 4 | 5 | public class ResidentQuestionTask extends TownyQuestionTask { 6 | protected Resident resident; 7 | 8 | public ResidentQuestionTask(Resident resident) { 9 | this.resident = resident; 10 | } 11 | 12 | public Resident getResident() { 13 | return resident; 14 | } 15 | 16 | @Override 17 | public void run() { 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/EmptyNationException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import com.palmergames.bukkit.towny.object.Nation; 4 | 5 | public class EmptyNationException extends Exception { 6 | private static final long serialVersionUID = 6093696939107516795L; 7 | private Nation nation; 8 | 9 | public EmptyNationException(Nation nation) { 10 | this.setNation(nation); 11 | } 12 | 13 | public void setNation(Nation nation) { 14 | this.nation = nation; 15 | } 16 | 17 | public Nation getNation() { 18 | return nation; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/TownyTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.TimerTask; 4 | 5 | import com.palmergames.bukkit.towny.Towny; 6 | import com.palmergames.bukkit.towny.object.TownyUniverse; 7 | 8 | public abstract class TownyTimerTask extends TimerTask { 9 | protected TownyUniverse universe; 10 | protected Towny plugin; 11 | 12 | public TownyTimerTask(TownyUniverse universe) { 13 | this.universe = universe; 14 | this.plugin = TownyUniverse.getPlugin(); 15 | } 16 | 17 | //@Override 18 | //public void run() { 19 | 20 | //} 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/event/CellAttackCanceledEvent.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.event; 2 | 3 | import org.bukkit.event.Event; 4 | 5 | import com.palmergames.bukkit.townywar.CellUnderAttack; 6 | 7 | 8 | public class CellAttackCanceledEvent extends Event { 9 | private static final long serialVersionUID = 2036661065011346448L; 10 | private CellUnderAttack cell; 11 | 12 | public CellAttackCanceledEvent(CellUnderAttack cell) { 13 | super("CellAttackCanceled"); 14 | this.cell = cell; 15 | 16 | } 17 | 18 | public CellUnderAttack getCell() { 19 | return cell; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/event/CellWonEvent.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.event; 2 | 3 | import org.bukkit.event.Event; 4 | 5 | import com.palmergames.bukkit.townywar.CellUnderAttack; 6 | 7 | 8 | public class CellWonEvent extends Event { 9 | private static final long serialVersionUID = 4691420283914184122L; 10 | private CellUnderAttack cellAttackData; 11 | 12 | public CellWonEvent(CellUnderAttack cellAttackData) { 13 | super("CellWon"); 14 | this.cellAttackData = cellAttackData; 15 | } 16 | 17 | public CellUnderAttack getCellAttackData() { 18 | return cellAttackData; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/ServerBroadCastTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | import java.util.TimerTask; 4 | 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.plugin.java.JavaPlugin; 7 | 8 | public class ServerBroadCastTimerTask extends TimerTask { 9 | private JavaPlugin plugin; 10 | private String msg; 11 | 12 | public ServerBroadCastTimerTask(JavaPlugin plugin, String msg) { 13 | this.plugin = plugin; 14 | this.msg = msg; 15 | } 16 | 17 | @Override 18 | public void run() { 19 | for (Player player : plugin.getServer().getOnlinePlayers()) 20 | player.sendMessage(msg); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/ArraySort.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | import java.util.Comparator; 4 | 5 | import org.bukkit.block.Block; 6 | 7 | /** 8 | * @author ElgarL 9 | * 10 | */ 11 | public class ArraySort implements Comparator { 12 | 13 | @Override 14 | public int compare(Block blockA, Block blockB) { 15 | 16 | return blockA.getY() - blockB.getY(); 17 | } 18 | private static ArraySort instance; 19 | 20 | public static ArraySort getInstance() { 21 | if (instance == null) { 22 | instance = new ArraySort(); 23 | } 24 | return instance; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/TownyQuestionTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import ca.xshade.bukkit.questioner.BukkitQuestionTask; 4 | import com.palmergames.bukkit.towny.Towny; 5 | import com.palmergames.bukkit.towny.object.TownyUniverse; 6 | 7 | public abstract class TownyQuestionTask extends BukkitQuestionTask { 8 | protected Towny towny; 9 | protected TownyUniverse universe; 10 | 11 | public TownyUniverse getUniverse() { 12 | return universe; 13 | } 14 | 15 | public void setTowny(Towny towny) { 16 | this.towny = towny; 17 | this.universe = towny.getTownyUniverse(); 18 | } 19 | 20 | @Override 21 | public abstract void run(); 22 | } 23 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/event/TownyWeatherListener.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.event; 2 | 3 | 4 | import org.bukkit.event.weather.LightningStrikeEvent; 5 | import org.bukkit.event.weather.WeatherListener; 6 | 7 | import com.palmergames.bukkit.towny.Towny; 8 | 9 | public class TownyWeatherListener extends WeatherListener { 10 | 11 | private final Towny plugin; 12 | 13 | public TownyWeatherListener(Towny instance) { 14 | plugin = instance; 15 | } 16 | 17 | @Override 18 | public void onLightningStrike(LightningStrikeEvent event) { 19 | 20 | } 21 | 22 | /** 23 | * @return the plugin 24 | */ 25 | public Towny getPlugin() { 26 | return plugin; 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/blockObject.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | public class blockObject { 4 | private int TypeID; 5 | private byte Data; 6 | 7 | blockObject (int typeID, byte data) { 8 | TypeID = typeID; 9 | Data = data; 10 | } 11 | 12 | /** 13 | * @return the typeID 14 | */ 15 | public int getTypeID() { 16 | return TypeID; 17 | } 18 | 19 | /** 20 | * @return the Data 21 | */ 22 | public byte getData() { 23 | return Data; 24 | } 25 | 26 | /** 27 | * @param typeID the typeID to set 28 | */ 29 | public void setTypeIdAndData(int typeID, byte data) { 30 | TypeID = typeID; 31 | Data = data; 32 | } 33 | 34 | 35 | 36 | 37 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/event/CellDefendedEvent.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.event; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.event.Event; 5 | 6 | import com.palmergames.bukkit.townywar.Cell; 7 | 8 | 9 | public class CellDefendedEvent extends Event { 10 | private static final long serialVersionUID = 257333278929768100L; 11 | private Player player; 12 | private Cell cell; 13 | 14 | public CellDefendedEvent(Player player, Cell cell) { 15 | super("CellDefended"); 16 | this.player = player; 17 | this.cell = cell; 18 | } 19 | 20 | public Player getPlayer() { 21 | return player; 22 | } 23 | 24 | public Cell getCell() { 25 | return cell; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/ResidentTownQuestionTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.object.Resident; 4 | import com.palmergames.bukkit.towny.object.Town; 5 | 6 | public class ResidentTownQuestionTask extends TownyQuestionTask { 7 | protected Resident resident; 8 | protected Town town; 9 | 10 | public ResidentTownQuestionTask(Resident resident, Town town) { 11 | this.resident = resident; 12 | this.town = town; 13 | } 14 | 15 | public Resident getResident() { 16 | return resident; 17 | } 18 | 19 | public Town getTown() { 20 | return town; 21 | } 22 | 23 | @Override 24 | public void run() { 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/blockqueue/BlockJob.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.blockqueue; 2 | 3 | import org.bukkit.World; 4 | 5 | class BlockJob { 6 | private String boss; 7 | private boolean notify; 8 | 9 | public BlockJob(String boss, World world) { 10 | this(boss, true); 11 | } 12 | 13 | public BlockJob(String boss, boolean notify) { 14 | this.setBoss(boss); 15 | this.setNotify(notify); 16 | } 17 | 18 | public void setBoss(String boss) { 19 | this.boss = boss; 20 | } 21 | 22 | public String getBoss() { 23 | return boss; 24 | } 25 | 26 | public void setNotify(boolean notify) { 27 | this.notify = notify; 28 | } 29 | 30 | public boolean isNotify() { 31 | return notify; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/ResidentNationQuestionTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.object.Resident; 4 | import com.palmergames.bukkit.towny.object.Nation; 5 | 6 | public class ResidentNationQuestionTask extends TownyQuestionTask { 7 | protected Resident resident; 8 | protected Nation nation; 9 | 10 | public ResidentNationQuestionTask(Resident resident, Nation nation) { 11 | this.resident = resident; 12 | this.nation = nation; 13 | } 14 | 15 | public Resident getResident() { 16 | return resident; 17 | } 18 | 19 | public Nation getNation() { 20 | return nation; 21 | } 22 | 23 | @Override 24 | public void run() { 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/listener/TownyWarEntityListener.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.listener; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.event.entity.EntityExplodeEvent; 5 | import org.bukkit.event.entity.EntityListener; 6 | 7 | 8 | import com.palmergames.bukkit.towny.Towny; 9 | import com.palmergames.bukkit.townywar.TownyWar; 10 | 11 | public class TownyWarEntityListener extends EntityListener { 12 | //private Towny plugin; 13 | 14 | public TownyWarEntityListener(Towny plugin) { 15 | //this.plugin = plugin; 16 | } 17 | 18 | @Override 19 | public void onEntityExplode(EntityExplodeEvent event) { 20 | for (Block block : event.blockList()) 21 | TownyWar.checkBlock(null, block, event); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/blockqueue/BlockWork.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.blockqueue; 2 | 3 | import org.bukkit.World; 4 | 5 | public class BlockWork { 6 | private World world; 7 | private int id, x, y, z; 8 | private byte data; 9 | 10 | public BlockWork(World world, int id, int x, int y, int z, byte data) { 11 | this.world = world; 12 | this.id = id; 13 | this.x = x; 14 | this.y = y; 15 | this.z = z; 16 | this.data = data; 17 | } 18 | 19 | public World getWorld() { 20 | return world; 21 | } 22 | 23 | public int getId() { 24 | return id; 25 | } 26 | 27 | public int getX() { 28 | return x; 29 | } 30 | 31 | public int getY() { 32 | return y; 33 | } 34 | 35 | public int getZ() { 36 | return z; 37 | } 38 | 39 | public byte getData() { 40 | return data; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/palmergames/util/MemMgmt.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | public class MemMgmt { 4 | public static String getMemoryBar(int size, Runtime run) { 5 | String line = ""; 6 | double percentUsed = (run.totalMemory() - run.freeMemory()) 7 | / run.maxMemory(); 8 | int pivot = (int) Math.floor(size * percentUsed); 9 | for (int i = 0; i < pivot - 1; i++) 10 | line += "="; 11 | if (pivot < size - 1) 12 | line += "+"; 13 | for (int i = pivot + 1; i < size; i++) 14 | line += "-"; 15 | return line; 16 | } 17 | 18 | public static String getMemSize(long num) { 19 | String[] s = { "By", "Kb", "Mb", "Gb", "Tb" }; 20 | double n = num; 21 | int w = 0; 22 | while (n > 1024 && w < s.length - 1) { 23 | n /= 1024; 24 | w += 1; 25 | } 26 | return String.format("%.2f %s", n, s[w]); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/NeedsPlaceholder.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.EnumSet; 4 | 5 | import org.bukkit.Material; 6 | 7 | public class NeedsPlaceholder { 8 | 9 | private static EnumSet needsPlaceholder = EnumSet.of( 10 | Material.SAND, 11 | Material.GRAVEL, 12 | Material.REDSTONE_WIRE, 13 | Material.DIODE_BLOCK_OFF, 14 | Material.DIODE_BLOCK_ON, 15 | Material.SAPLING, 16 | Material.BROWN_MUSHROOM, 17 | Material.RED_MUSHROOM, 18 | Material.CROPS, 19 | Material.REDSTONE_TORCH_OFF, 20 | Material.REDSTONE_TORCH_ON, 21 | Material.SNOW 22 | ); 23 | 24 | public static boolean contains(Material material) { 25 | //System.out.print("needsPlaceholder - " + needsPlaceholder.size()); 26 | return (needsPlaceholder.contains(material)); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/CellAttackThread.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar; 2 | 3 | 4 | public class CellAttackThread extends Thread { 5 | CellUnderAttack cell; 6 | boolean running = false; 7 | 8 | public CellAttackThread(CellUnderAttack cellUnderAttack) { 9 | this.cell = cellUnderAttack; 10 | } 11 | 12 | @Override 13 | public void run() { 14 | running = true; 15 | cell.drawFlag(); 16 | while (running) { 17 | try { 18 | Thread.sleep(TownyWarConfig.getTimeBetweenFlagColorChange()); 19 | } catch (InterruptedException e) { 20 | return; 21 | } 22 | if (running) { 23 | cell.changeFlag(); 24 | if (cell.hasEnded()) { 25 | TownyWar.attackWon(cell); 26 | } 27 | } 28 | } 29 | } 30 | 31 | protected void setRunning(boolean running) { 32 | this.running = running; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownyObservableType.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | /** 4 | * @author dumptruckman 5 | */ 6 | public enum TownyObservableType { 7 | // TownyObject 8 | OBJECT_NAME, 9 | 10 | // TownyUniverse 11 | NEW_DAY, 12 | TOGGLE_MOB_REMOVAL, 13 | TOGGLE_DAILY_TIMER, 14 | TOGGLE_HEALTH_REGEN, 15 | TOGGLE_TELEPORT_WARMUP, 16 | PLAYER_LOGIN, 17 | PLAYER_LOGOUT, 18 | NEW_RESIDENT, 19 | NEW_TOWN, 20 | NEW_NATION, 21 | NEW_WORLD, 22 | RENAME_TOWN, 23 | RENAME_NATION, 24 | COLLECTED_NATION_TAX, 25 | COLLECTED_TONW_TAX, 26 | WAR_START, 27 | WAR_END, 28 | WAR_CLEARED, 29 | WAR_SET, 30 | REMOVE_NATION, 31 | REMOVE_TOWN, 32 | REMOVE_RESIDENT, 33 | REMOVE_TOWN_BLOCK, 34 | UPKEEP_NATION, 35 | UPKEEP_TOWN, 36 | TELEPORT_REQUEST, 37 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/Colors.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | import org.bukkit.ChatColor; 4 | 5 | public class Colors { 6 | public static final String Black = "\u00A70"; 7 | public static final String Navy = "\u00A71"; 8 | public static final String Green = "\u00A72"; 9 | public static final String Blue = "\u00A73"; 10 | public static final String Red = "\u00A74"; 11 | public static final String Purple = "\u00A75"; 12 | public static final String Gold = "\u00A76"; 13 | public static final String LightGray = "\u00A77"; 14 | public static final String Gray = "\u00A78"; 15 | public static final String DarkPurple = "\u00A79"; 16 | public static final String LightGreen = "\u00A7a"; 17 | public static final String LightBlue = "\u00A7b"; 18 | public static final String Rose = "\u00A7c"; 19 | public static final String LightPurple = "\u00A7d"; 20 | public static final String Yellow = "\u00A7e"; 21 | public static final String White = "\u00A7f"; 22 | 23 | public static String strip(String line) { 24 | for (ChatColor cc : ChatColor.values()) 25 | line.replaceAll(cc.toString(), ""); 26 | return line; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/SetDefaultModes.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.bukkit.entity.Player; 6 | 7 | import com.palmergames.bukkit.towny.object.TownyUniverse; 8 | import com.palmergames.bukkit.towny.permissions.PermissionNodes; 9 | 10 | /** 11 | * @author ElgarL 12 | * 13 | */ 14 | public class SetDefaultModes extends TownyTimerTask { 15 | protected Player player; 16 | protected boolean notify; 17 | 18 | public SetDefaultModes(TownyUniverse universe, Player player, boolean notify) { 19 | super(universe); 20 | this.player = player; 21 | this.notify = notify; 22 | } 23 | 24 | @Override 25 | public void run() { 26 | 27 | // Is the player still available 28 | if (!Arrays.asList(TownyUniverse.getOnlinePlayers()).contains(this.player)) 29 | return; 30 | 31 | //setup default modes 32 | String[] modes = TownyUniverse.getPermissionSource().getPlayerPermissionStringNode(player.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 33 | plugin.setPlayerMode(player, modes, notify); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/EmptyTownException.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import com.palmergames.bukkit.towny.object.Town; 4 | 5 | public class EmptyTownException extends Exception { 6 | private static final long serialVersionUID = 5058583908170407803L; 7 | private EmptyNationException emptyNationException; 8 | private Town town; 9 | 10 | public EmptyTownException(Town town) { 11 | setTown(town); 12 | } 13 | 14 | public EmptyTownException(Town town, 15 | EmptyNationException emptyNationException) { 16 | setTown(town); 17 | setEmptyNationException(emptyNationException); 18 | } 19 | 20 | public boolean hasEmptyNationException() { 21 | return emptyNationException != null; 22 | } 23 | 24 | public EmptyNationException getEmptyNationException() { 25 | return emptyNationException; 26 | } 27 | 28 | public void setEmptyNationException( 29 | EmptyNationException emptyNationException) { 30 | this.emptyNationException = emptyNationException; 31 | } 32 | 33 | public void setTown(Town town) { 34 | this.town = town; 35 | } 36 | 37 | public Town getTown() { 38 | return town; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/TownyLogFormatter.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.text.DateFormat; 6 | import java.util.Date; 7 | import java.util.logging.LogRecord; 8 | import java.util.logging.SimpleFormatter; 9 | 10 | public class TownyLogFormatter extends SimpleFormatter { 11 | private DateFormat dateFormat; 12 | static final String lineSep = System.getProperty("line.separator"); 13 | 14 | @Override 15 | public synchronized String format(LogRecord record) { 16 | StringBuffer buf = new StringBuffer(180); 17 | if (dateFormat == null) 18 | dateFormat = DateFormat.getDateTimeInstance(); 19 | 20 | buf.append('['); 21 | buf.append(dateFormat.format(new Date(record.getMillis()))); 22 | buf.append("] "); 23 | buf.append(formatMessage(record)); 24 | buf.append(lineSep); 25 | 26 | Throwable throwable = record.getThrown(); 27 | if (throwable != null) { 28 | StringWriter sink = new StringWriter(); 29 | throwable.printStackTrace(new PrintWriter(sink, true)); 30 | buf.append(sink.toString()); 31 | } 32 | return buf.toString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/Compass.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | public class Compass { 4 | public enum Point { 5 | N, 6 | NE, 7 | E, 8 | SE, 9 | S, 10 | SW, 11 | W, 12 | NW 13 | } 14 | public static Compass.Point getCompassPointForDirection(double inDegrees) { 15 | double degrees = (inDegrees - 90) % 360 ; 16 | if (degrees < 0) 17 | degrees += 360; 18 | 19 | if (0 <= degrees && degrees < 22.5) 20 | return Compass.Point.W; 21 | else if (22.5 <= degrees && degrees < 67.5) 22 | return Compass.Point.NW; 23 | else if (67.5 <= degrees && degrees < 112.5) 24 | return Compass.Point.N; 25 | else if (112.5 <= degrees && degrees < 157.5) 26 | return Compass.Point.NE; 27 | else if (157.5 <= degrees && degrees < 202.5) 28 | return Compass.Point.E; 29 | else if (202.5 <= degrees && degrees < 247.5) 30 | return Compass.Point.SE; 31 | else if (247.5 <= degrees && degrees < 292.5) 32 | return Compass.Point.S; 33 | else if (292.5 <= degrees && degrees < 337.5) 34 | return Compass.Point.SW; 35 | else if (337.5 <= degrees && degrees < 360.0) 36 | return Compass.Point.W; 37 | else 38 | return null; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/TownyMoneyLogFormatter.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | import java.text.DateFormat; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Date; 8 | import java.util.logging.LogRecord; 9 | import java.util.logging.SimpleFormatter; 10 | 11 | public class TownyMoneyLogFormatter extends SimpleFormatter { 12 | private DateFormat dateFormat; 13 | static final String lineSep = System.getProperty("line.separator"); 14 | 15 | @Override 16 | public synchronized String format(LogRecord record) { 17 | StringBuffer buf = new StringBuffer(180); 18 | if (dateFormat == null) 19 | dateFormat = new SimpleDateFormat("MMM dd '-' HH:mm:ss"); 20 | 21 | buf.append(dateFormat.format(new Date(record.getMillis()))); 22 | buf.append(","); 23 | buf.append(formatMessage(record)); 24 | buf.append(lineSep); 25 | 26 | Throwable throwable = record.getThrown(); 27 | if (throwable != null) { 28 | StringWriter sink = new StringWriter(); 29 | throwable.printStackTrace(new PrintWriter(sink, true)); 30 | buf.append(sink.toString()); 31 | } 32 | return buf.toString(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/JoinTownTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 4 | import com.palmergames.bukkit.towny.TownyException; 5 | import com.palmergames.bukkit.towny.TownyMessaging; 6 | import com.palmergames.bukkit.towny.TownySettings; 7 | import com.palmergames.bukkit.towny.object.Resident; 8 | import com.palmergames.bukkit.towny.object.Town; 9 | import com.palmergames.bukkit.towny.object.TownyUniverse; 10 | import com.palmergames.bukkit.util.ChatTools; 11 | 12 | public class JoinTownTask extends ResidentTownQuestionTask { 13 | 14 | public JoinTownTask(Resident resident, Town town) { 15 | super(resident, town); 16 | } 17 | 18 | @Override 19 | public void run() { 20 | try { 21 | town.addResident(resident); 22 | towny.deleteCache(resident.getName()); 23 | TownyUniverse.getDataSource().saveResident(resident); 24 | TownyUniverse.getDataSource().saveTown(town); 25 | 26 | TownyMessaging.sendTownMessage(town, ChatTools.color(String.format(TownySettings.getLangString("msg_join_town"), resident.getName()))); 27 | } catch (AlreadyRegisteredException e) { 28 | try { 29 | TownyMessaging.sendResidentMessage(resident, e.getMessage()); 30 | } catch (TownyException e1) { 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/blockqueue/BlockQueue.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.blockqueue; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.bukkit.Server; 6 | 7 | public class BlockQueue { 8 | private LinkedList queue = new LinkedList(); 9 | private static volatile BlockQueue instance; 10 | private BlockWorker worker; 11 | 12 | public synchronized void addWork(Object obj) { 13 | queue.addLast(obj); 14 | notify(); 15 | } 16 | 17 | public synchronized Object getWork() throws InterruptedException { 18 | while (queue.isEmpty()) 19 | wait(); 20 | return queue.removeFirst(); 21 | } 22 | 23 | public static BlockQueue getInstance() throws Exception { 24 | if (instance == null) 25 | throw new Exception("BlockQueue has not been initialized yet"); 26 | 27 | return instance; 28 | } 29 | 30 | public static BlockQueue newInstance(Server server) { 31 | instance = new BlockQueue(); 32 | instance.worker = new BlockWorker(server, instance); 33 | 34 | //TODO: Fix 35 | //TODO: null = plugin 36 | //TODO: null = plugin 37 | //TODO: null = plugin 38 | //TODO: null = plugin 39 | //TODO: null = plugin 40 | server.getScheduler().scheduleAsyncDelayedTask(null, instance.getWorker()); 41 | 42 | return instance; 43 | } 44 | 45 | public BlockWorker getWorker() { 46 | return worker; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/BlockLocation.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.World; 5 | 6 | /** 7 | * A class to hold basic block location data 8 | * 9 | * @author ElgarL 10 | */ 11 | public class BlockLocation { 12 | public void setY(int y) { 13 | this.y = y; 14 | } 15 | 16 | protected int x, z, y; 17 | protected World world; 18 | 19 | public BlockLocation(Location loc) { 20 | this.x = loc.getBlockX(); 21 | this.z = loc.getBlockZ(); 22 | this.y = loc.getBlockY(); 23 | this.world = loc.getWorld(); 24 | } 25 | 26 | public int getX() { 27 | return x; 28 | } 29 | 30 | public int getZ() { 31 | return z; 32 | } 33 | 34 | public int getY() { 35 | return y; 36 | } 37 | 38 | public World getWorld() { 39 | return world; 40 | } 41 | 42 | public boolean isLocation(Location loc) { 43 | 44 | if ((loc.getWorld() == getWorld()) 45 | && (loc.getBlockX() == getX()) 46 | && (loc.getBlockY() == getY()) 47 | && (loc.getBlockZ() == getZ())) 48 | return true; 49 | 50 | return false; 51 | } 52 | 53 | public boolean isLocation(BlockLocation blockLocation) { 54 | 55 | if ((blockLocation.getWorld() == getWorld()) 56 | && (blockLocation.getX() == getX()) 57 | && (blockLocation.getY() == getY()) 58 | && (blockLocation.getZ() == getZ())) 59 | return true; 60 | 61 | return false; 62 | } 63 | 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/event/CellAttackEvent.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.event; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.Cancellable; 6 | import org.bukkit.event.Event; 7 | 8 | import com.palmergames.bukkit.townywar.CellUnderAttack; 9 | 10 | 11 | public class CellAttackEvent extends Event implements Cancellable { 12 | private static final long serialVersionUID = -6413227132896218785L; 13 | private Player player; 14 | private Block flagBaseBlock; 15 | private boolean cancel = false; 16 | private String reason = null; 17 | 18 | public CellAttackEvent(Player player, Block flagBaseBlock) { 19 | super("CellAttack"); 20 | this.player = player; 21 | this.flagBaseBlock = flagBaseBlock; 22 | } 23 | 24 | public Player getPlayer() { 25 | return player; 26 | } 27 | 28 | public Block getFlagBaseBlock() { 29 | return flagBaseBlock; 30 | } 31 | 32 | public CellUnderAttack getData() { 33 | return new CellUnderAttack(player.getName(), flagBaseBlock); 34 | } 35 | 36 | @Override 37 | public boolean isCancelled() { 38 | return cancel; 39 | } 40 | 41 | @Override 42 | public void setCancelled(boolean cancel) { 43 | this.cancel = cancel; 44 | } 45 | 46 | public String getReason() { 47 | return reason; 48 | } 49 | 50 | public void setReason(String reason) { 51 | this.reason = reason; 52 | } 53 | 54 | public boolean hasReason() { 55 | return reason != null; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/PermissionEventEnums.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | /** 4 | * @author ElgarL 5 | * 6 | */ 7 | public class PermissionEventEnums { 8 | 9 | // GroupManager Event Enums 10 | public enum GMUser_Action { 11 | //USER_PERMISSIONS_CHANGED, 12 | USER_INHERITANCE_CHANGED, 13 | USER_INFO_CHANGED, 14 | USER_GROUP_CHANGED, 15 | USER_SUBGROUP_CHANGED, 16 | USER_ADDED, 17 | //USER_REMOVED, 18 | } 19 | 20 | public enum GMGroup_Action { 21 | //GROUP_PERMISSIONS_CHANGED, 22 | GROUP_INHERITANCE_CHANGED, 23 | GROUP_INFO_CHANGED, 24 | //GROUP_ADDED, 25 | //GROUP_REMOVED, 26 | } 27 | 28 | public enum GMSystem_Action { 29 | RELOADED, 30 | //SAVED, 31 | DEFAULT_GROUP_CHANGED, 32 | //VALIDATE_TOGGLE, 33 | } 34 | 35 | // PermissionsEX Event Enums 36 | public enum PEXEntity_Action { 37 | PERMISSIONS_CHANGED, 38 | OPTIONS_CHANGED, 39 | INHERITANCE_CHANGED, 40 | INFO_CHANGED, 41 | TIMEDPERMISSION_EXPIRED, 42 | RANK_CHANGED, 43 | DEFAULTGROUP_CHANGED, 44 | WEIGHT_CHANGED, 45 | SAVED, 46 | REMOVED, 47 | } 48 | 49 | public enum PEXSystem_Action { 50 | //BACKEND_CHANGED, 51 | RELOADED, 52 | WORLDINHERITANCE_CHANGED, 53 | DEFAULTGROUP_CHANGED, 54 | //DEBUGMODE_TOGGLE, 55 | } 56 | 57 | 58 | } -------------------------------------------------------------------------------- /src/com/palmergames/util/JavaUtil.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | import com.palmergames.util.JavaUtil; 10 | 11 | public class JavaUtil { 12 | 13 | /** 14 | * Recursively check if the interface inherits the super interface. Returns false if not an interface. Returns true if sup = sub. 15 | * 16 | * @param sup The class of the interface you think it is a subinterface of. 17 | * @param sub The possible subinterface of the super interface. 18 | * @return true if it is a subinterface. 19 | */ 20 | 21 | public static boolean isSubInterface(Class sup, Class sub) { 22 | if (sup.isInterface() && sub.isInterface()) { 23 | if (sup.equals(sub)) 24 | return true; 25 | for (Class c : sub.getInterfaces()) 26 | if (isSubInterface(sup, c)) 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | public static List readTextFromJar(String path) throws IOException { 33 | BufferedReader fin = new BufferedReader( 34 | new InputStreamReader( 35 | JavaUtil.class.getResourceAsStream( 36 | path))); 37 | String line; 38 | List out = new ArrayList(); 39 | try { 40 | while ((line = fin.readLine()) != null) 41 | out.add(line); 42 | } catch (IOException e) { 43 | throw new IOException(e.getCause()); 44 | } finally { 45 | fin.close(); 46 | } 47 | return out; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/palmergames/util/KeyValueTable.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.Hashtable; 6 | import java.util.List; 7 | 8 | import com.palmergames.util.KeyValue; 9 | import com.palmergames.util.Sorting; 10 | 11 | public class KeyValueTable { 12 | private List> keyValues = new ArrayList>(); 13 | 14 | public List> getKeyValues() { 15 | return keyValues; 16 | } 17 | 18 | public void setKeyValues(List> keyValues) { 19 | this.keyValues = keyValues; 20 | } 21 | 22 | public KeyValueTable() { 23 | } 24 | 25 | public KeyValueTable(Hashtable table) { 26 | this(new ArrayList(table.keySet()), new ArrayList(table.values())); 27 | } 28 | 29 | public KeyValueTable(List keys, List values) { 30 | //if (keys.size() != values.size()) 31 | // throw new Exception(); 32 | 33 | for (int i = 0; i < keys.size(); i++) 34 | keyValues.add(new KeyValue(keys.get(i), values.get(i))); 35 | } 36 | 37 | public void put(K key, V value) { 38 | keyValues.add(new KeyValue(key, value)); 39 | } 40 | 41 | public void add(KeyValue keyValue) { 42 | keyValues.add(keyValue); 43 | } 44 | 45 | public void sortByKey() { 46 | Collections.sort(keyValues, new Sorting.KeySort()); 47 | } 48 | 49 | public void sortByValue() { 50 | Collections.sort(keyValues, new Sorting.ValueSort()); 51 | } 52 | 53 | public void revese() { 54 | Collections.reverse(keyValues); 55 | } 56 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownyObject.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | import java.util.Observable; 7 | 8 | import com.palmergames.bukkit.towny.TownyFormatter; 9 | 10 | public abstract class TownyObject extends Observable { 11 | private String name; 12 | private boolean isChangedName = true; 13 | 14 | public void setName(String name) { 15 | setChanged(); 16 | notifyObservers(TownyObservableType.OBJECT_NAME); 17 | this.name = name; 18 | setChangedName(true); 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public List getTreeString(int depth) { 26 | return new ArrayList(); 27 | } 28 | 29 | public String getTreeDepth(int depth) { 30 | char[] fill = new char[depth*4]; 31 | Arrays.fill(fill, ' '); 32 | if (depth > 0) { 33 | fill[0] = '|'; 34 | int offset = (depth-1)*4; 35 | fill[offset] = '+'; 36 | fill[offset+1] = '-'; 37 | fill[offset+2] = '-'; 38 | } 39 | return new String(fill); 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return getName(); 45 | } 46 | 47 | public String getFormattedName() { 48 | return TownyFormatter.getFormattedName(this); 49 | } 50 | 51 | /** 52 | * @return the isChangedName 53 | */ 54 | public boolean isChangedName() { 55 | return isChangedName; 56 | } 57 | 58 | /** 59 | * @param isChangedName the isChangedName to set 60 | */ 61 | public void setChangedName(boolean isChangedName) { 62 | this.isChangedName = isChangedName; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/questioner/JoinNationTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.questioner; 2 | 3 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 4 | import com.palmergames.bukkit.towny.NotRegisteredException; 5 | import com.palmergames.bukkit.towny.TownyException; 6 | import com.palmergames.bukkit.towny.TownyMessaging; 7 | import com.palmergames.bukkit.towny.TownySettings; 8 | import com.palmergames.bukkit.towny.object.Resident; 9 | import com.palmergames.bukkit.towny.object.Nation; 10 | import com.palmergames.bukkit.towny.object.TownyUniverse; 11 | import com.palmergames.bukkit.util.ChatTools; 12 | 13 | public class JoinNationTask extends ResidentNationQuestionTask { 14 | 15 | public JoinNationTask(Resident resident, Nation nation) { 16 | super(resident, nation); 17 | } 18 | 19 | @Override 20 | public void run() { 21 | try { 22 | nation.addTown(resident.getTown()); 23 | //towny.deleteCache(resident.getName()); 24 | TownyUniverse.getDataSource().saveResident(resident); 25 | TownyUniverse.getDataSource().saveTown(resident.getTown()); 26 | TownyUniverse.getDataSource().saveNation(nation); 27 | 28 | TownyMessaging.sendNationMessage(nation, ChatTools.color(String.format(TownySettings.getLangString("msg_join_nation"), resident.getTown().getName()))); 29 | } catch (AlreadyRegisteredException e) { 30 | try { 31 | TownyMessaging.sendResidentMessage(resident, e.getMessage()); 32 | } catch (TownyException e1) { 33 | } 34 | } catch (NotRegisteredException e) { 35 | // TODO somehow this person is not the town mayor 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/TimeTools.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | /** 6 | * @author dumptruckman 7 | */ 8 | public class TimeTools { 9 | 10 | /** 11 | * This will parse a time string such as 2d30m to an equivalent amount of seconds. 12 | * @param dhms The time string 13 | * @return The amount of seconds 14 | */ 15 | public static long secondsFromDhms(String dhms) { 16 | int seconds = 0, minutes = 0, hours = 0, days = 0; 17 | if (dhms.contains("d")) { 18 | days = Integer.parseInt(dhms.split("d")[0].replaceAll(" ", "")); 19 | if (dhms.contains("h") || dhms.contains("m") || dhms.contains("s")) { 20 | dhms = dhms.split("d")[1]; 21 | } 22 | } 23 | if (dhms.contains("h")) { 24 | hours = Integer.parseInt(dhms.split("h")[0].replaceAll(" ", "")); 25 | if (dhms.contains("m") || dhms.contains("s")) { 26 | dhms = dhms.split("h")[1]; 27 | } 28 | } 29 | if (dhms.contains("m")) { 30 | minutes = Integer.parseInt(dhms.split("m")[0].replaceAll(" ", "")); 31 | if (dhms.contains("s")) { 32 | dhms = dhms.split("m")[1]; 33 | } 34 | } 35 | if (dhms.contains("s")) { 36 | seconds = Integer.parseInt(dhms.split("s")[0].replaceAll(" ", "")); 37 | } 38 | return (days * 86400) + (hours * 3600) + (minutes * 60) + seconds; 39 | } 40 | 41 | public static long getMillis(String dhms) { 42 | if (Pattern.matches(".*[a-zA-Z].*", dhms)) { 43 | return (TimeTools.secondsFromDhms(dhms) * 1000); 44 | } 45 | return Long.parseLong(dhms); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/db/TownySQLTown.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.db; 2 | 3 | import com.avaje.ebean.validation.Length; 4 | import com.avaje.ebean.validation.NotEmpty; 5 | import com.avaje.ebean.validation.NotNull; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | //import org.bukkit.Bukkit; 10 | //import org.bukkit.entity.Player; 11 | 12 | /** 13 | * 14 | * @author FuzzeWuzze 15 | */ 16 | @Entity() 17 | @Table(name = "towny_towns") 18 | public class TownySQLTown { 19 | 20 | @Id 21 | private int id; 22 | @NotNull 23 | private String playerName; 24 | @Length(max = 30) 25 | @NotEmpty 26 | private String name; 27 | 28 | @NotEmpty 29 | private int id_Mayor; 30 | 31 | @NotEmpty 32 | private int totalBlocks; 33 | 34 | @NotEmpty 35 | private int id_Home; 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public String getPlayerName() { 46 | return playerName; 47 | } 48 | 49 | public void setPlayerName(String playerName) { 50 | this.playerName = playerName; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public void setName(String name) { 58 | this.name = name; 59 | } 60 | 61 | public int getId_Mayor() { 62 | return id_Mayor; 63 | } 64 | 65 | public void setId_Mayor(int id_Mayor) { 66 | this.id_Mayor = id_Mayor; 67 | } 68 | 69 | public int getTotalBlocks() { 70 | return totalBlocks; 71 | } 72 | 73 | public void setTotalBlocks(int totalBlocks) { 74 | this.totalBlocks = totalBlocks; 75 | } 76 | 77 | public int getId_Home() { 78 | return id_Home; 79 | } 80 | 81 | public void setId_Home(int id_Home) { 82 | this.id_Home = id_Home; 83 | } 84 | } -------------------------------------------------------------------------------- /src/com/palmergames/util/Sorting.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | import java.util.Comparator; 4 | import java.util.Hashtable; 5 | 6 | import com.palmergames.util.KeyValue; 7 | import com.palmergames.util.KeyValueTable; 8 | 9 | public class Sorting { 10 | 11 | @SuppressWarnings({ "rawtypes", "unchecked" }) 12 | public static void main(String[] args) { 13 | Hashtable table = new Hashtable(); 14 | table.put(1, 4); 15 | table.put(0, 3); 16 | table.put(3, 0); 17 | table.put(2, 2); 18 | table.put(4, 1); 19 | 20 | KeyValueTable kvTable = new KeyValueTable(table); 21 | print(kvTable); 22 | kvTable.sortByKey();print(kvTable); 23 | kvTable.sortByValue();print(kvTable); 24 | } 25 | 26 | public static void print(KeyValueTable table) { 27 | for (KeyValue index : table.getKeyValues()) 28 | System.out.print("[" + index.key + " : " + index.value + "]\n"); 29 | System.out.print("\n"); 30 | } 31 | 32 | static class ValueSort implements Comparator { 33 | @Override 34 | public int compare(Object o1, Object o2) { 35 | if (!(o1 instanceof KeyValue && o2 instanceof KeyValue)) 36 | return o1.hashCode() - o2.hashCode(); 37 | 38 | KeyValue k1 = (KeyValue)o1; 39 | KeyValue k2 = (KeyValue)o2; 40 | return k1.value.hashCode() - k2.value.hashCode(); 41 | } 42 | } 43 | 44 | static class KeySort implements Comparator { 45 | @Override 46 | public int compare(Object o1, Object o2) { 47 | if (!(o1 instanceof KeyValue && o2 instanceof KeyValue)) 48 | return o1.hashCode() - o2.hashCode(); 49 | 50 | KeyValue k1 = (KeyValue)o1; 51 | KeyValue k2 = (KeyValue)o2; 52 | return k1.key.hashCode() - k2.key.hashCode(); 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/WorldCoord.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import com.palmergames.bukkit.towny.NotRegisteredException; 4 | 5 | 6 | //TODO: have toString() include the worlds? 7 | public class WorldCoord extends Coord { 8 | private TownyWorld world; 9 | 10 | public TownyWorld getWorld() { 11 | return world; 12 | } 13 | 14 | public void setWorld(TownyWorld world) { 15 | this.world = world; 16 | } 17 | 18 | public WorldCoord(TownyWorld world, int x, int z) { 19 | super(x,z); 20 | this.world = world; 21 | } 22 | 23 | public WorldCoord(TownyWorld world, Coord coord) { 24 | super(coord); 25 | this.world = world; 26 | } 27 | 28 | public WorldCoord(WorldCoord worldCoord) { 29 | super(worldCoord); 30 | this.world = worldCoord.getWorld(); 31 | } 32 | 33 | public Coord getCoord() { 34 | return new Coord(x, z); 35 | } 36 | 37 | public TownBlock getTownBlock() throws NotRegisteredException { 38 | return getWorld().getTownBlock(getCoord()); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | int result = 17; 44 | result = 31 * result + x; 45 | result = 31 * result + z; 46 | result = 31 * result + world.hashCode(); 47 | return result; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object obj) { 52 | if (obj == this) 53 | return true; 54 | if (!(obj instanceof Coord)) 55 | return false; 56 | 57 | if (!(obj instanceof WorldCoord)) { 58 | Coord o = (Coord) obj; 59 | return this.x == o.x && this.z == o.z; 60 | } 61 | 62 | WorldCoord o = (WorldCoord) obj; 63 | return this.x == o.x && this.z == o.z && this.world.equals(o.world); 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return world.getName() + "," + super.toString(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownBlockOwner.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 7 | import com.palmergames.bukkit.towny.NotRegisteredException; 8 | 9 | public class TownBlockOwner extends TownyEconomyObject { 10 | protected List townBlocks = new ArrayList(); 11 | protected TownyPermission permissions = new TownyPermission(); 12 | 13 | public void setTownblocks(List townblocks) { 14 | this.townBlocks = townblocks; 15 | } 16 | 17 | public List getTownBlocks() { 18 | return townBlocks; 19 | } 20 | 21 | public boolean hasTownBlock(TownBlock townBlock) { 22 | return townBlocks.contains(townBlock); 23 | } 24 | 25 | public void addTownBlock(TownBlock townBlock) throws AlreadyRegisteredException { 26 | if (hasTownBlock(townBlock)) 27 | throw new AlreadyRegisteredException(); 28 | else 29 | townBlocks.add(townBlock); 30 | } 31 | 32 | public void removeTownBlock(TownBlock townBlock) throws NotRegisteredException { 33 | if (!hasTownBlock(townBlock)) 34 | throw new NotRegisteredException(); 35 | else 36 | townBlocks.remove(townBlock); 37 | } 38 | 39 | public void setPermissions(String line) { 40 | //permissions.reset(); not needed, already done in permissions.load() 41 | permissions.load(line); 42 | } 43 | 44 | public TownyPermission getPermissions() { 45 | return permissions; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/event/TownyWorldListener.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.event; 2 | 3 | import org.bukkit.event.world.WorldListener; 4 | import org.bukkit.event.world.WorldLoadEvent; 5 | import org.bukkit.event.world.WorldInitEvent; 6 | 7 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 8 | import com.palmergames.bukkit.towny.NotRegisteredException; 9 | import com.palmergames.bukkit.towny.Towny; 10 | import com.palmergames.bukkit.towny.TownyMessaging; 11 | import com.palmergames.bukkit.towny.object.TownyUniverse; 12 | import com.palmergames.bukkit.towny.object.TownyWorld; 13 | 14 | public class TownyWorldListener extends WorldListener { 15 | //private final Towny plugin; 16 | 17 | public TownyWorldListener(Towny instance) { 18 | //plugin = instance; 19 | } 20 | 21 | @Override 22 | public void onWorldLoad(WorldLoadEvent event) { 23 | newWorld(event.getWorld().getName()); 24 | } 25 | 26 | @Override 27 | public void onWorldInit(WorldInitEvent event) { 28 | newWorld(event.getWorld().getName()); 29 | 30 | } 31 | 32 | private void newWorld(String worldName) { 33 | 34 | //String worldName = event.getWorld().getName(); 35 | try { 36 | TownyUniverse.getDataSource().newWorld(worldName); 37 | TownyWorld world = TownyUniverse.getDataSource().getWorld(worldName); 38 | if (world == null) 39 | TownyMessaging.sendErrorMsg("Could not create data for " + worldName); 40 | else { 41 | if (!TownyUniverse.getDataSource().loadWorld(world)) { 42 | // First time world has been noticed 43 | TownyUniverse.getDataSource().saveWorld(world); 44 | } 45 | } 46 | } catch (AlreadyRegisteredException e) { 47 | // Allready loaded 48 | } catch (NotRegisteredException e) { 49 | TownyMessaging.sendErrorMsg("Could not create data for " + worldName); 50 | e.printStackTrace(); 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/NullPermSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.palmergames.bukkit.towny.Towny; 6 | import com.palmergames.bukkit.towny.object.Resident; 7 | 8 | 9 | 10 | public class NullPermSource extends TownyPermissionSource { 11 | 12 | public NullPermSource(Towny towny) { 13 | this.plugin = towny; 14 | } 15 | 16 | @Override 17 | public String getPrefixSuffix(Resident resident, String node) { 18 | // using no permissions provider 19 | return ""; 20 | } 21 | 22 | /** 23 | * 24 | * @param playerName 25 | * @param node 26 | * @return -1 = can't find 27 | */ 28 | @Override 29 | public int getGroupPermissionIntNode(String playerName, String node) { 30 | // // using no permissions provider 31 | return -1; 32 | } 33 | 34 | /** 35 | * 36 | * @param playerName 37 | * @param node 38 | * @return empty = can't find 39 | */ 40 | @Override 41 | public String getPlayerPermissionStringNode(String playerName, String node) { 42 | // // using no permissions provider 43 | return ""; 44 | } 45 | 46 | 47 | /** hasPermission 48 | * 49 | * returns if a player has a certain permission node. 50 | * 51 | * @param player 52 | * @param node 53 | * @return null as we are not using permissions 54 | */ 55 | @Override 56 | public boolean hasPermission(Player player, String node) { 57 | // using no permissions provider 58 | return false; 59 | } 60 | 61 | /** 62 | * Returns the players Group name. 63 | * 64 | * @param player 65 | * @return empty as we are using no permissions 66 | */ 67 | @Override 68 | public String getPlayerGroup(Player player) { 69 | // using no permissions provider 70 | return ""; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/RepeatingTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.ArrayList; 4 | 5 | import com.palmergames.bukkit.towny.NotRegisteredException; 6 | import com.palmergames.bukkit.towny.TownyLogger; 7 | import com.palmergames.bukkit.towny.object.PlotBlockData; 8 | import com.palmergames.bukkit.towny.object.TownBlock; 9 | import com.palmergames.bukkit.towny.object.TownyRegenAPI; 10 | import com.palmergames.bukkit.towny.object.TownyUniverse; 11 | 12 | public class RepeatingTimerTask extends TownyTimerTask { 13 | 14 | public RepeatingTimerTask(TownyUniverse universe) { 15 | super(universe); 16 | } 17 | 18 | @Override 19 | public void run() { 20 | // Perform a single block regen in each regen area, if any are left to do. 21 | if (TownyRegenAPI.hasPlotChunks()) { 22 | for (PlotBlockData plotChunk : new ArrayList(TownyRegenAPI.getPlotChunks().values())) { 23 | if (!plotChunk.restoreNextBlock()) { 24 | TownyRegenAPI.deletePlotChunk(plotChunk); 25 | TownyRegenAPI.deletePlotChunkSnapshot(plotChunk); 26 | } 27 | } 28 | } 29 | 30 | // Take a snapshot of the next townBlock and save. 31 | if (TownyRegenAPI.hasWorldCoords()) { 32 | try { 33 | TownBlock townBlock = TownyRegenAPI.getWorldCoord().getTownBlock(); 34 | PlotBlockData plotChunk = new PlotBlockData(townBlock); 35 | plotChunk.initialize(); // Create a new snapshot. 36 | 37 | if (!plotChunk.getBlockList().isEmpty() && !(plotChunk.getBlockList() == null)) 38 | TownyRegenAPI.addPlotChunkSnapshot(plotChunk); // Save the snapshot. 39 | 40 | plotChunk = null; 41 | 42 | townBlock.setLocked(false); 43 | TownyUniverse.getDataSource().saveTownBlock(townBlock); 44 | plugin.updateCache(); 45 | 46 | if (!TownyRegenAPI.hasWorldCoords()) 47 | TownyLogger.log.info("Plot snapshots completed."); 48 | 49 | } catch (NotRegisteredException e) { 50 | // Not a townblock so ignore. 51 | } 52 | 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/ResidentPurge.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.ArrayList; 4 | 5 | import org.bukkit.command.CommandSender; 6 | 7 | import com.palmergames.bukkit.towny.Towny; 8 | import com.palmergames.bukkit.towny.TownyMessaging; 9 | import com.palmergames.bukkit.towny.object.Resident; 10 | import com.palmergames.bukkit.towny.object.TownyUniverse; 11 | 12 | 13 | /** 14 | * @author ElgarL 15 | * 16 | */ 17 | public class ResidentPurge extends Thread { 18 | 19 | Towny plugin; 20 | private CommandSender sender = null; 21 | long deleteTime; 22 | 23 | /** 24 | * @param plugin reference to towny 25 | */ 26 | public ResidentPurge(Towny plugin, CommandSender sender, long deleteTime) { 27 | super(); 28 | this.plugin = plugin; 29 | this.deleteTime = deleteTime; 30 | this.setPriority(MIN_PRIORITY); 31 | } 32 | 33 | @Override 34 | public void run() { 35 | 36 | int count = 0; 37 | 38 | message("Scanning for old residents..."); 39 | for (Resident resident : new ArrayList(TownyUniverse.getDataSource().getResidents())) { 40 | if (!resident.isNPC() 41 | && (System.currentTimeMillis() - resident.getLastOnline() > (this.deleteTime)) && !plugin.isOnline(resident.getName()) 42 | && !plugin.isOnline(resident.getName())) { 43 | count++; 44 | message("Deleting resident: " + resident.getName()); 45 | TownyUniverse.getDataSource().removeResident(resident); 46 | TownyUniverse.getDataSource().removeResidentList(resident); 47 | 48 | } 49 | } 50 | 51 | message("Resident purge complete: " + count + " deleted."); 52 | 53 | } 54 | 55 | private void message(String msg) { 56 | 57 | if (this.sender != null) 58 | TownyMessaging.sendMessage(this.sender, msg); 59 | else 60 | TownyMessaging.sendMsg(msg); 61 | 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/HealthRegenTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.Server; 5 | import org.bukkit.entity.Player; 6 | import org.bukkit.event.entity.EntityRegainHealthEvent; 7 | import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; 8 | 9 | import com.palmergames.bukkit.towny.TownyException; 10 | import com.palmergames.bukkit.towny.object.Coord; 11 | import com.palmergames.bukkit.towny.object.TownBlock; 12 | import com.palmergames.bukkit.towny.object.TownBlockType; 13 | import com.palmergames.bukkit.towny.object.TownyUniverse; 14 | import com.palmergames.bukkit.towny.object.TownyWorld; 15 | 16 | public class HealthRegenTimerTask extends TownyTimerTask { 17 | 18 | private Server server; 19 | 20 | public HealthRegenTimerTask(TownyUniverse universe, Server server) { 21 | super(universe); 22 | this.server = server; 23 | } 24 | 25 | @Override 26 | public void run() { 27 | if (universe.isWarTime()) 28 | return; 29 | 30 | for (Player player : server.getOnlinePlayers()) { 31 | if (player.getHealth() <= 0) 32 | continue; 33 | 34 | Coord coord = Coord.parseCoord(player); 35 | try { 36 | TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName()); 37 | TownBlock townBlock = world.getTownBlock(coord); 38 | 39 | if (universe.isAlly(townBlock.getTown(), TownyUniverse.getDataSource().getResident(player.getName()).getTown())) 40 | if (!townBlock.getType().equals(TownBlockType.ARENA)) // only regen if not in an arena 41 | incHealth(player); 42 | } catch (TownyException x) { 43 | } 44 | } 45 | 46 | //if (TownySettings.getDebug()) 47 | // System.out.println("[Towny] Debug: Health Regen"); 48 | } 49 | 50 | public void incHealth(Player player) { 51 | int currentHP = player.getHealth(); 52 | if (currentHP < 20) { 53 | player.setHealth(++currentHP); 54 | 55 | // Raise an event so other plugins can keep in sync. 56 | EntityRegainHealthEvent event = new EntityRegainHealthEvent(player, ++currentHP, RegainReason.REGEN); 57 | Bukkit.getServer().getPluginManager().callEvent(event); 58 | 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/util/MinecraftTools.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.util; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | 11 | import org.bukkit.Bukkit; 12 | import org.bukkit.Server; 13 | import org.bukkit.World; 14 | import org.bukkit.block.Block; 15 | import org.bukkit.entity.Player; 16 | 17 | import com.palmergames.bukkit.towny.TownySettings; 18 | 19 | /** 20 | * A class of functions related to minecraft in general. 21 | * 22 | * @author Shade (Chris H) 23 | * @version 1.0 24 | */ 25 | 26 | public class MinecraftTools { 27 | /** 28 | * Converts Seconds to Ticks 29 | * @param t 30 | * @return ticks 31 | */ 32 | public static long convertToTicks(long t) { 33 | return t * 20; 34 | } 35 | 36 | public static HashMap getPlayersPerWorld(Server server) { 37 | HashMap m = new HashMap(); 38 | for (World world : server.getWorlds()) 39 | m.put(world.getName(), 0); 40 | for (Player player : server.getOnlinePlayers()) 41 | m.put(player.getWorld().getName(), m.get(player.getWorld().getName()) + 1); 42 | return m; 43 | } 44 | 45 | public static Block getBlockOffset(Block block, int xOffset, int yOffset, int zOffset) { 46 | return block.getWorld().getBlockAt(block.getX()+xOffset, block.getY()+yOffset, block.getZ()+zOffset); 47 | } 48 | 49 | public static List getWhiteListedUsers() { 50 | List names = new ArrayList(); 51 | try { 52 | BufferedReader fin = new BufferedReader(new FileReader("white-list.txt")); 53 | 54 | try { 55 | String line; 56 | while ((line = fin.readLine()) != null) 57 | names.add(line); 58 | } catch (IOException e) { 59 | } 60 | 61 | try { 62 | fin.close(); 63 | } catch (IOException e) { 64 | } 65 | } catch (FileNotFoundException e) { 66 | } 67 | return names; 68 | } 69 | 70 | public static boolean isOnline(String playerName) { 71 | return Bukkit.getServer().getPlayer(playerName) != null; 72 | } 73 | 74 | public static int calcChunk(int value) { 75 | 76 | return (value * TownySettings.getTownBlockSize())/16; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/com/palmergames/util/TimeMgmt.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class TimeMgmt { 7 | public final static long[][] defaultCountdownDelays = new long[][] { 8 | { 10, 1 }, // <= 10s, Warn every 1s 9 | { 30, 5 }, // <= 30s, Warn every 5s 10 | { 60, 10 }, // <= minute, Warn every 10s 11 | { 5 * 60, 60 }, // <= 5 minutes, Warn every minute 12 | { 30 * 60, 5 * 60 }, // <= 30 minutes, Warn every 5 minutes 13 | { 60 * 60, 10 * 60 }, // <= 60 minutes, Warn every 10 minutes 14 | { 24 * 60 * 60, 60 * 60 }, // <= day, Warn every hour 15 | { Integer.MAX_VALUE, 24 * 60 * 60 } // <= max, Warn every day 16 | }; 17 | 18 | public static List getCountdownDelays(int start) { 19 | return getCountdownDelays(start, defaultCountdownDelays); 20 | } 21 | 22 | // TODO: Throw specific exception 23 | // TODO: Faster loop, check if next warning is belong the delay index 24 | public static List getCountdownDelays(int start, long[][] delays) { 25 | List out = new ArrayList(); 26 | for (int d = 0; d < delays.length; d++) 27 | if (delays[d].length != 2) 28 | return null; 29 | 30 | Integer lastDelayIndex = null; 31 | long nextWarningAt = Integer.MAX_VALUE; 32 | for (long t = start; t > 0; t--) { 33 | for (int d = 0; d < delays.length; d++) { 34 | if (t <= delays[d][0]) { 35 | if (lastDelayIndex == null || t <= nextWarningAt 36 | || d < lastDelayIndex) { 37 | lastDelayIndex = d; 38 | nextWarningAt = t - delays[d][1]; 39 | out.add(new Long(t)); 40 | break; 41 | } 42 | } 43 | } 44 | } 45 | 46 | return out; 47 | } 48 | 49 | public static String formatCountdownTime(long l) { 50 | String out = ""; 51 | if (l >= 3600) { 52 | int h = (int) Math.floor(l / 3600); 53 | out = h + " hours"; 54 | l -= h * 3600; 55 | } 56 | if (l >= 60) { 57 | int m = (int) Math.floor(l / 60); 58 | out += (out.length() > 0 ? ", " : "") + m + " minutes"; 59 | l -= m * 60; 60 | } 61 | if (out.length() == 0 || l > 0) 62 | out += (out.length() > 0 ? ", " : "") + l + " seconds"; 63 | return out; 64 | } 65 | 66 | public static void main(String[] args) { 67 | for (Long l : getCountdownDelays(36000000, defaultCountdownDelays)) 68 | System.out.println(l + " " + formatCountdownTime(l)); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/listener/TownyWarBlockListener.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.listener; 2 | 3 | import org.bukkit.block.Block; 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.event.block.BlockBreakEvent; 6 | import org.bukkit.event.block.BlockBurnEvent; 7 | import org.bukkit.event.block.BlockListener; 8 | import org.bukkit.event.block.BlockPistonExtendEvent; 9 | import org.bukkit.event.block.BlockPistonRetractEvent; 10 | import org.bukkit.event.block.BlockPlaceEvent; 11 | 12 | 13 | import com.palmergames.bukkit.towny.Towny; 14 | import com.palmergames.bukkit.townywar.TownyWar; 15 | import com.palmergames.bukkit.townywar.TownyWarConfig; 16 | import com.palmergames.bukkit.townywar.event.CellAttackEvent; 17 | 18 | public class TownyWarBlockListener extends BlockListener { 19 | private Towny plugin; 20 | 21 | public TownyWarBlockListener(Towny plugin) { 22 | this.plugin = plugin; 23 | } 24 | 25 | /** 26 | * For Testing purposes only. 27 | */ 28 | @Override 29 | public void onBlockPlace(BlockPlaceEvent event) { 30 | Player player = event.getPlayer(); 31 | Block block = event.getBlockPlaced(); 32 | 33 | if (block == null) 34 | return; 35 | 36 | if (block.getType() == TownyWarConfig.getFlagBaseMaterial()) { 37 | int topY = block.getWorld().getHighestBlockYAt(block.getX(), block.getZ()) - 1; 38 | if (block.getY() >= topY) { 39 | CellAttackEvent cellAttackEvent = new CellAttackEvent(player, block); 40 | this.plugin.getServer().getPluginManager().callEvent(cellAttackEvent); 41 | if (cellAttackEvent.isCancelled()) { 42 | event.setBuild(false); 43 | event.setCancelled(true); 44 | } 45 | } 46 | } 47 | } 48 | 49 | @Override 50 | public void onBlockBreak(BlockBreakEvent event) { 51 | TownyWar.checkBlock(event.getPlayer(), event.getBlock(), event); 52 | } 53 | 54 | @Override 55 | public void onBlockBurn(BlockBurnEvent event) { 56 | TownyWar.checkBlock(null, event.getBlock(), event); 57 | } 58 | 59 | @Override 60 | public void onBlockPistonExtend(BlockPistonExtendEvent event) { 61 | for (Block block : event.getBlocks()) 62 | TownyWar.checkBlock(null, block, event); 63 | } 64 | 65 | /** 66 | * TODO: Need to check if a immutable block is being moved with a sticky piston. 67 | */ 68 | @Override 69 | public void onBlockPistonRetract(BlockPistonRetractEvent event) { 70 | 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/Cell.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar; 2 | 3 | import org.bukkit.Location; 4 | 5 | import com.palmergames.bukkit.towny.object.Coord; 6 | 7 | public class Cell { 8 | private String worldName; 9 | private int x, z; 10 | 11 | public Cell(String worldName, int x, int z) { 12 | this.worldName = worldName; 13 | this.x = x; 14 | this.z = z; 15 | } 16 | 17 | public Cell(Cell cell) { 18 | this.worldName = cell.getWorldName(); 19 | this.x = cell.getX(); 20 | this.z = cell.getZ(); 21 | } 22 | 23 | public Cell(Location location) { 24 | this(Cell.parse(location)); 25 | } 26 | 27 | public int getX() { 28 | return x; 29 | } 30 | 31 | public void setX(int x) { 32 | this.x = x; 33 | } 34 | 35 | public int getZ() { 36 | return z; 37 | } 38 | 39 | public void setZ(int z) { 40 | this.z = z; 41 | } 42 | 43 | public String getWorldName() { 44 | return worldName; 45 | } 46 | 47 | public void setWorldName(String worldName) { 48 | this.worldName = worldName; 49 | } 50 | 51 | public static Cell parse(String worldName, int x, int z) { 52 | int cellSize = Coord.getCellSize(); 53 | int xresult = x / cellSize; 54 | int zresult = z / cellSize; 55 | boolean xneedfix = x % cellSize != 0; 56 | boolean zneedfix = z % cellSize != 0; 57 | return new Cell(worldName, xresult - (x < 0 && xneedfix ? 1 : 0), zresult - (z < 0 && zneedfix ? 1 : 0)); 58 | } 59 | 60 | public static Cell parse(Location loc) { 61 | return parse(loc.getWorld().getName(), loc.getBlockX(), loc.getBlockZ()); 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | int hash = 17; 67 | hash = hash * 27 + (worldName == null ? 0 : worldName.hashCode()); 68 | hash = hash * 27 + x; 69 | hash = hash * 27 + z; 70 | return hash; 71 | } 72 | 73 | @Override 74 | public boolean equals(Object obj) { 75 | if (obj == this) 76 | return true; 77 | if (!(obj instanceof Cell)) 78 | return false; 79 | 80 | Cell that = (Cell) obj; 81 | return this.x == that.x 82 | && this.z == that.z 83 | && (this.worldName == null ? that.worldName == null : this.worldName.equals(that.worldName)); 84 | } 85 | 86 | public boolean isUnderAttack() { 87 | return TownyWar.isUnderAttack(this); 88 | } 89 | 90 | public CellUnderAttack getAttackData() { 91 | return TownyWar.getAttackData(this); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/blockqueue/BlockWorker.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.blockqueue; 2 | 3 | import org.bukkit.Server; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.entity.Player; 6 | 7 | public class BlockWorker implements Runnable { 8 | private BlockQueue blockQueue; 9 | private Server server; 10 | public static final Object NO_MORE_WORK = new Object(); 11 | public static final Object END_JOB = new Object(); 12 | 13 | private boolean running; 14 | 15 | private BlockJob currentJob; 16 | private int blocks, skipped; 17 | 18 | public BlockWorker(Server server, BlockQueue blockQueue) { 19 | this.blockQueue = blockQueue; 20 | this.setServer(server); 21 | setRunning(true); 22 | } 23 | 24 | public synchronized void setRunning(boolean running) { 25 | this.running = running; 26 | } 27 | 28 | @Override 29 | public void run() { 30 | blocks = 0; 31 | skipped = 0; 32 | 33 | try { 34 | while (running) { 35 | Object obj = blockQueue.getWork(); 36 | 37 | if (obj == NO_MORE_WORK) 38 | break; 39 | 40 | if (obj == END_JOB) 41 | onJobFinish(currentJob); 42 | 43 | if (obj instanceof BlockWork) { 44 | try { 45 | buildBlock((BlockWork) obj); 46 | } catch (Exception e) { 47 | skipped++; 48 | } 49 | ; 50 | blocks++; 51 | } 52 | 53 | if (obj instanceof BlockJob) { 54 | currentJob = (BlockJob) obj; 55 | blocks = 0; 56 | skipped = 0; 57 | } 58 | } 59 | } catch (InterruptedException e) { 60 | } 61 | ; 62 | 63 | System.out.println("[Blocker] BlockQueue Thread stopped."); 64 | blockQueue = null; 65 | } 66 | 67 | public void buildBlock(BlockWork blockWork) { 68 | Block block = blockWork.getWorld().getBlockAt(blockWork.getX(), blockWork.getY(), blockWork.getZ()); 69 | 70 | if (blockWork.getId() == block.getTypeId()) 71 | return; 72 | 73 | // TODO: Set block 74 | block.setTypeId(blockWork.getId()); 75 | block.setData(blockWork.getData()); 76 | } 77 | 78 | public void setServer(Server server) { 79 | this.server = server; 80 | } 81 | 82 | public Server getServer() { 83 | return server; 84 | } 85 | 86 | public void onJobFinish(BlockJob job) { 87 | if (job.isNotify()) { 88 | Player player = getServer().getPlayer(job.getBoss()); 89 | player.sendMessage("Generated: " + blocks + " Blocks"); 90 | if (skipped > 0) 91 | player.sendMessage("Skipped: " + skipped + " Blocks"); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownSpawnLevel.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.palmergames.bukkit.config.ConfigNodes; 6 | import com.palmergames.bukkit.towny.Towny; 7 | import com.palmergames.bukkit.towny.TownyException; 8 | import com.palmergames.bukkit.towny.TownySettings; 9 | import com.palmergames.bukkit.towny.permissions.PermissionNodes; 10 | 11 | public enum TownSpawnLevel { 12 | TOWN_RESIDENT(ConfigNodes.GTOWN_SETTINGS_ALLOW_TOWN_SPAWN, "msg_err_town_spawn_forbidden", ConfigNodes.ECO_PRICE_TOWN_SPAWN_TRAVEL, PermissionNodes.TOWNY_SPAWN_TOWN.getNode()), 13 | PART_OF_NATION(ConfigNodes.GTOWN_SETTINGS_ALLOW_TOWN_SPAWN_TRAVEL_NATION, "msg_err_town_spawn_nation_forbidden", ConfigNodes.ECO_PRICE_TOWN_SPAWN_TRAVEL_NATION, PermissionNodes.TOWNY_SPAWN_NATION.getNode()), 14 | NATION_ALLY(ConfigNodes.GTOWN_SETTINGS_ALLOW_TOWN_SPAWN_TRAVEL_ALLY, "msg_err_town_spawn_ally_forbidden", ConfigNodes.ECO_PRICE_TOWN_SPAWN_TRAVEL_ALLY, PermissionNodes.TOWNY_SPAWN_ALLY.getNode()), 15 | UNAFFILIATED(ConfigNodes.GTOWN_SETTINGS_ALLOW_TOWN_SPAWN_TRAVEL, "msg_err_public_spawn_forbidden", ConfigNodes.ECO_PRICE_TOWN_SPAWN_TRAVEL_PUBLIC, PermissionNodes.TOWNY_SPAWN_PUBLIC.getNode()), 16 | ADMIN(null, null, null, null); 17 | 18 | private ConfigNodes isAllowingConfigNode, ecoPriceConfigNode; 19 | private String permissionNode, notAllowedLangNode; 20 | 21 | private TownSpawnLevel(ConfigNodes isAllowingConfigNode, String notAllowedLangNode, ConfigNodes ecoPriceConfigNode, String permissionNode) { 22 | this.isAllowingConfigNode = isAllowingConfigNode; 23 | this.notAllowedLangNode = notAllowedLangNode; 24 | this.ecoPriceConfigNode = ecoPriceConfigNode; 25 | this.permissionNode = permissionNode; 26 | } 27 | 28 | public void checkIfAllowed(Towny plugin, Player player) throws TownyException { 29 | if (!(isAllowed() && hasPermissionNode(plugin, player))) 30 | throw new TownyException(TownySettings.getLangString(notAllowedLangNode)); 31 | } 32 | 33 | public boolean isAllowed() { 34 | return this == TownSpawnLevel.ADMIN ? true : TownySettings.getBoolean(this.isAllowingConfigNode); 35 | } 36 | 37 | public boolean hasPermissionNode(Towny plugin, Player player) { 38 | return this == TownSpawnLevel.ADMIN ? true : (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(player, this.permissionNode)) 39 | || ((!plugin.isPermissions()) && (TownySettings.isAllowingTownSpawn())); 40 | } 41 | 42 | public double getCost() { 43 | return this == TownSpawnLevel.ADMIN ? 0 : TownySettings.getDouble(ecoPriceConfigNode); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/Coord.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.entity.Entity; 6 | 7 | /** 8 | * A class to hold and calculate coordinates in a grid according to the size defined in 9 | * the static field size. 10 | * 11 | * @author Shade 12 | */ 13 | public class Coord { 14 | protected static int cellSize = 16; 15 | protected int x, z; 16 | 17 | public Coord(int x, int z) { 18 | this.x = x; 19 | this.z = z; 20 | } 21 | 22 | public Coord(Coord coord) { 23 | this.x = coord.getX(); 24 | this.z = coord.getZ(); 25 | } 26 | 27 | public int getX() { 28 | return x; 29 | } 30 | 31 | public void setX(int x) { 32 | this.x = x; 33 | } 34 | 35 | public int getZ() { 36 | return z; 37 | } 38 | 39 | public void setZ(int z) { 40 | this.z = z; 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | int result = 17; 46 | result = 27 * result + x; 47 | result = 27 * result + z; 48 | return result; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | if (obj == this) 54 | return true; 55 | if (!(obj instanceof Coord)) 56 | return false; 57 | 58 | Coord o = (Coord) obj; 59 | return this.x == o.x && this.z == o.z; 60 | } 61 | 62 | 63 | 64 | /* 65 | * OLD METHOD 66 | 67 | public static Coord parseCoord(int x, int z) { 68 | return new Coord(x / getCellSize() - (x < 0 ? 1 : 0), z / getCellSize() - (z < 0 ? 1 : 0)); 69 | } 70 | */ 71 | 72 | /** 73 | * Convert regular grid coordinates to their grid cell's counterparts. 74 | * 75 | * @param x 76 | * @param z 77 | * @return a new instance of Coord. 78 | * 79 | */ 80 | public static Coord parseCoord(int x, int z) { 81 | int xresult = x / getCellSize(); 82 | int zresult = z / getCellSize(); 83 | boolean xneedfix = x % getCellSize()!=0; 84 | boolean zneedfix = z % getCellSize()!=0; 85 | return new Coord(xresult - (x < 0 && xneedfix ? 1 : 0), zresult - (z < 0 && zneedfix ? 1 : 0)); 86 | } 87 | 88 | public static Coord parseCoord(Entity entity) { 89 | return parseCoord(entity.getLocation()); 90 | } 91 | 92 | public static Coord parseCoord(Location loc) { 93 | return parseCoord(loc.getBlockX(), loc.getBlockZ()); 94 | } 95 | 96 | public static Coord parseCoord(Block block) { 97 | return parseCoord(block.getX(), block.getZ()); 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return getX() + "," + getZ(); 103 | } 104 | 105 | public static void setCellSize(int cellSize) { 106 | Coord.cellSize = cellSize; 107 | } 108 | 109 | public static int getCellSize() { 110 | return cellSize; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownBlockType.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.EnumSet; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | /** 8 | * @author dumptruckman 9 | */ 10 | public enum TownBlockType { 11 | RESIDENTIAL(0, "default", "+") { // The default Block Type. 12 | }, 13 | 14 | COMMERCIAL(1, "Shop", "C") { // Just like residential but has additional tax 15 | @Override 16 | public double getTax(Town town) { 17 | return town.getCommercialPlotTax() + town.getPlotTax(); 18 | } 19 | }, 20 | 21 | ARENA(2, "arena", "A"){ //Always PVP enabled. 22 | }, 23 | 24 | EMBASSY(3, "embassy", "E") { // For other towns to own a plot in your town. 25 | @Override 26 | public double getTax(Town town) { 27 | return town.getEmbassyPlotTax() + town.getPlotTax(); 28 | } 29 | }, 30 | WILDS(4, "wilds", "W"){ //Follows wilderness protection settings, but town owned. 31 | }, 32 | SPLEEF(5, "spleef", "+"){ //Follows wilderness protection settings, but town owned. 33 | }, 34 | // These are subject to change: 35 | /* 36 | PUBLIC(6, "") { // Will have it's own permission set 37 | }, 38 | 39 | MINE(7, "") { // Will have it's own permission set within a y range 40 | }, 41 | 42 | HOTEL(8, "") { // Will stack multiple y-ranges and function like a micro town 43 | }, 44 | 45 | JAIL(9, "") { // Where people will spawn when they die in enemy (neutral) towns 46 | },*/ 47 | ; 48 | 49 | private int id; 50 | private String name, asciiMapKey; 51 | private static final Map idLookup 52 | = new HashMap(); 53 | private static final Map nameLookup 54 | = new HashMap(); 55 | 56 | TownBlockType(int id, String name, String asciiMapKey) { 57 | this.id = id; 58 | this.name = name; 59 | this.asciiMapKey = asciiMapKey; 60 | } 61 | 62 | static { 63 | for(TownBlockType s : EnumSet.allOf(TownBlockType.class)) { 64 | idLookup.put(s.getId(), s); 65 | nameLookup.put(s.toString().toLowerCase(), s); 66 | } 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return name; 72 | } 73 | 74 | public double getTax(Town town) { 75 | return town.getPlotTax(); 76 | } 77 | 78 | public int getId() { 79 | return id; 80 | } 81 | 82 | public String getAsciiMapKey() { 83 | return asciiMapKey; 84 | } 85 | 86 | public static TownBlockType lookup(int id) { 87 | return idLookup.get(id); 88 | } 89 | 90 | public static TownBlockType lookup(String name) { 91 | return nameLookup.get(name.toLowerCase()); 92 | } 93 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/war/WarTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.war; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.palmergames.bukkit.towny.NotRegisteredException; 6 | import com.palmergames.bukkit.towny.TownyMessaging; 7 | import com.palmergames.bukkit.towny.TownySettings; 8 | import com.palmergames.bukkit.towny.object.Coord; 9 | import com.palmergames.bukkit.towny.object.Nation; 10 | import com.palmergames.bukkit.towny.object.Resident; 11 | import com.palmergames.bukkit.towny.object.TownBlock; 12 | import com.palmergames.bukkit.towny.object.TownyUniverse; 13 | import com.palmergames.bukkit.towny.object.WorldCoord; 14 | import com.palmergames.bukkit.towny.tasks.TownyTimerTask; 15 | 16 | public class WarTimerTask extends TownyTimerTask { 17 | War warEvent; 18 | 19 | public WarTimerTask(War warEvent) { 20 | super(warEvent.getTownyUniverse()); 21 | this.warEvent = warEvent; 22 | } 23 | 24 | @Override 25 | public void run() { 26 | //TODO: check if war has ended and end gracefully 27 | if (!warEvent.isWarTime()) { 28 | warEvent.end(); 29 | universe.clearWarEvent(); 30 | TownyUniverse.getPlugin().updateCache(); 31 | TownyMessaging.sendDebugMsg("War ended."); 32 | return; 33 | } 34 | 35 | int numPlayers = 0; 36 | for (Player player : TownyUniverse.getOnlinePlayers()) { 37 | numPlayers += 1; 38 | TownyMessaging.sendDebugMsg("[War] "+player.getName()+": "); 39 | try { 40 | Resident resident = TownyUniverse.getDataSource().getResident(player.getName()); 41 | if (resident.hasNation()) { 42 | Nation nation = resident.getTown().getNation(); 43 | TownyMessaging.sendDebugMsg("[War] hasNation"); 44 | if (nation.isNeutral()) { 45 | if (warEvent.isWarringNation(nation)) 46 | warEvent.nationLeave(nation); 47 | continue; 48 | } 49 | TownyMessaging.sendDebugMsg("[War] notNeutral"); 50 | if (!warEvent.isWarringNation(nation)) 51 | continue; 52 | TownyMessaging.sendDebugMsg("[War] warringNation"); 53 | //TODO: Cache player coord & townblock 54 | 55 | WorldCoord worldCoord = new WorldCoord(TownyUniverse.getDataSource().getWorld(player.getWorld().getName()), Coord.parseCoord(player)); 56 | if (!warEvent.isWarZone(worldCoord)) 57 | continue; 58 | TownyMessaging.sendDebugMsg("[War] warZone"); 59 | if (player.getLocation().getBlockY() < TownySettings.getMinWarHeight()) 60 | continue; 61 | TownyMessaging.sendDebugMsg("[War] aboveMinHeight"); 62 | TownBlock townBlock = worldCoord.getTownBlock(); //universe.getWorld(player.getWorld().getName()).getTownBlock(worldCoord); 63 | if (nation == townBlock.getTown().getNation() || townBlock.getTown().getNation().hasAlly(nation)) 64 | continue; 65 | TownyMessaging.sendDebugMsg("[War] notAlly"); 66 | //Enemy nation 67 | warEvent.damage(resident.getTown(), townBlock); 68 | TownyMessaging.sendDebugMsg("[War] damaged"); 69 | } 70 | } catch(NotRegisteredException e) { 71 | continue; 72 | } 73 | } 74 | 75 | TownyMessaging.sendDebugMsg("[War] # Players: " + numPlayers); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/TownyLogger.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import java.io.IOException; 4 | import java.util.logging.FileHandler; 5 | import java.util.logging.Formatter; 6 | import java.util.logging.Handler; 7 | import java.util.logging.Logger; 8 | 9 | import com.palmergames.bukkit.towny.object.Nation; 10 | import com.palmergames.bukkit.towny.object.Resident; 11 | import com.palmergames.bukkit.towny.object.Town; 12 | import com.palmergames.bukkit.towny.object.TownyEconomyObject; 13 | import com.palmergames.util.FileMgmt; 14 | 15 | public class TownyLogger { 16 | public static final Logger log = Logger.getLogger("com.palmergames.bukkit.towny.log"); 17 | public static final Logger money = Logger.getLogger("com.palmergames.bukkit.towny.moneylog"); 18 | public static final Logger debug = Logger.getLogger("com.palmergames.bukkit.towny.debug"); 19 | 20 | public static void setup(String root, boolean append) { 21 | String logFolder = root + FileMgmt.fileSeparator() + "logs"; 22 | //FileMgmt.checkFolders(new String[]{logFolder}); 23 | 24 | setupLogger(log, logFolder, "towny.log", new TownyLogFormatter(), TownySettings.isAppendingToLog()); 25 | 26 | setupLogger(money, logFolder, "money.csv", new TownyMoneyLogFormatter(), TownySettings.isAppendingToLog()); 27 | money.setUseParentHandlers(false); 28 | 29 | //if (TownySettings.getDebug()) { 30 | setupLogger(debug, logFolder, "debug.log", new TownyLogFormatter(), TownySettings.isAppendingToLog()); 31 | //debug.setUseParentHandlers(false); //if enabled this prevents the messages from showing in the console. 32 | //} 33 | } 34 | 35 | public static void shutDown() { 36 | CloseDownLogger(log); 37 | CloseDownLogger(money); 38 | CloseDownLogger(debug); 39 | } 40 | 41 | 42 | public static void setupLogger(Logger logger, String logFolder, String filename, Formatter formatter, boolean append) { 43 | try { 44 | FileHandler fh = new FileHandler(logFolder + FileMgmt.fileSeparator() + filename, append); 45 | fh.setFormatter(formatter); 46 | logger.addHandler(fh); 47 | } catch (IOException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | 52 | public static void CloseDownLogger(Logger logger) { 53 | 54 | for (Handler fh: logger.getHandlers()) { 55 | logger.removeHandler(fh); 56 | fh.close(); 57 | } 58 | 59 | } 60 | 61 | public static void logMoneyTransaction(TownyEconomyObject a, double amount, TownyEconomyObject b, String reason) { 62 | money.info(String.format("%s,%s,%s,%s", reason == null ? "" : reason, getObjectName(a), amount, getObjectName(b))); 63 | //money.info(String.format(" %-48s --[ %16.2f ]--> %-48s", getObjectName(a), amount, getObjectName(b))); 64 | } 65 | 66 | private static String getObjectName(TownyEconomyObject obj) { 67 | String type; 68 | if (obj == null) 69 | type = "Server"; 70 | else if (obj instanceof Resident) 71 | type = "Resident"; 72 | else if (obj instanceof Town) 73 | type = "Town"; 74 | else if (obj instanceof Nation) 75 | type = "Nation"; 76 | else 77 | type = "Server"; 78 | 79 | return String.format("[%s] %s", type, obj != null ? obj.getName() : ""); 80 | } 81 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/TeleportWarmupTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import com.palmergames.bukkit.towny.EconomyException; 4 | import com.palmergames.bukkit.towny.TownyException; 5 | import com.palmergames.bukkit.towny.TownyMessaging; 6 | import com.palmergames.bukkit.towny.TownySettings; 7 | import com.palmergames.bukkit.towny.object.Resident; 8 | import com.palmergames.bukkit.towny.object.Town; 9 | import com.palmergames.bukkit.towny.object.TownyUniverse; 10 | 11 | import java.util.ArrayDeque; 12 | import java.util.Queue; 13 | 14 | import org.bukkit.Chunk; 15 | 16 | /** 17 | * @author dumptruckman 18 | */ 19 | public class TeleportWarmupTimerTask extends TownyTimerTask { 20 | 21 | private static Queue teleportQueue; 22 | 23 | public TeleportWarmupTimerTask(TownyUniverse universe) { 24 | super(universe); 25 | teleportQueue = new ArrayDeque(); 26 | } 27 | 28 | @Override 29 | public void run() { 30 | long currentTime = System.currentTimeMillis(); 31 | 32 | while (true) { 33 | Resident resident = teleportQueue.peek(); 34 | if (resident == null) break; 35 | if (currentTime > resident.getTeleportRequestTime() + (TownySettings.getTeleportWarmupTime() * 1000)) { 36 | resident.clearTeleportRequest(); 37 | try { 38 | // Make sure the chunk we teleport to is loaded. 39 | Chunk chunk = resident.getTeleportDestination().getSpawn().getWorld().getChunkAt(resident.getTeleportDestination().getSpawn().getBlock()); 40 | if (!chunk.isLoaded()) chunk.load(); 41 | TownyUniverse.getPlayer(resident).teleport(resident.getTeleportDestination().getSpawn()); 42 | } catch (TownyException ignore) { } 43 | teleportQueue.poll(); 44 | } else { 45 | break; 46 | } 47 | } 48 | } 49 | 50 | public static void requestTeleport(Resident resident, Town town, double cost) { 51 | resident.setTeleportRequestTime(); 52 | resident.setTeleportDestination(town); 53 | try { 54 | teleportQueue.add(resident); 55 | } catch (NullPointerException e) { 56 | System.out.println("[Towny] Error: Null returned from teleport queue."); 57 | System.out.println(e.getStackTrace()); 58 | } 59 | } 60 | 61 | public static void abortTeleportRequest(Resident resident) { 62 | if (resident != null && teleportQueue.contains(resident)) { 63 | teleportQueue.remove(resident); 64 | if ((resident.getTeleportCost() != 0) && (TownySettings.isUsingEconomy())) { 65 | try { 66 | resident.collect(resident.getTeleportCost(), TownySettings.getLangString("msg_cost_spawn_refund")); 67 | resident.setTeleportCost(0); 68 | TownyMessaging.sendResidentMessage(resident, TownySettings.getLangString("msg_cost_spawn_refund")); 69 | } catch (EconomyException e) { 70 | // Economy error trap 71 | e.printStackTrace(); 72 | } catch (TownyException e) { 73 | // Resident not registered exception. 74 | } 75 | 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/com/palmergames/util/StringMgmt.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.util; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Useful functions related to strings, or arrays of them. 7 | * 8 | * @author Shade (Chris H) 9 | * @version 1.4 10 | */ 11 | 12 | public class StringMgmt { 13 | 14 | @SuppressWarnings("rawtypes") 15 | public static String join(List arr) { 16 | return join(arr, " "); 17 | } 18 | 19 | @SuppressWarnings("rawtypes") 20 | public static String join(List arr, String separator) { 21 | if (arr == null || arr.size() == 0) 22 | return ""; 23 | String out = arr.get(0).toString(); 24 | for (int i = 1; i < arr.size(); i++) 25 | out += separator + arr.get(i); 26 | return out; 27 | } 28 | 29 | public static String join(Object[] arr) { 30 | return join(arr, " "); 31 | } 32 | 33 | public static String join(Object[] arr, String separator) { 34 | if (arr.length == 0) 35 | return ""; 36 | String out = arr[0].toString(); 37 | for (int i = 1; i < arr.length; i++) 38 | out += separator + arr[i]; 39 | return out; 40 | } 41 | 42 | public static String[] remFirstArg(String[] arr) { 43 | return remArgs(arr, 1); 44 | } 45 | 46 | public static String[] remLastArg(String[] arr) { 47 | return subArray(arr, 0, arr.length-1); 48 | } 49 | 50 | public static String[] remArgs(String[] arr, int startFromIndex) { 51 | if (arr.length == 0) 52 | return arr; 53 | else if (arr.length < startFromIndex) 54 | return new String[0]; 55 | else { 56 | String[] newSplit = new String[arr.length - startFromIndex]; 57 | System.arraycopy(arr, startFromIndex, newSplit, 0, arr.length - startFromIndex); 58 | return newSplit; 59 | } 60 | } 61 | 62 | public static String[] subArray(String[] arr, int start, int end) { 63 | //assert start > end; 64 | //assert start >= 0; 65 | //assert end < args.length; 66 | if (arr.length == 0) 67 | return arr; 68 | else if (end < start) 69 | return new String[0]; 70 | else { 71 | int length = end - start; 72 | String[] newSplit = new String[length]; 73 | System.arraycopy(arr, start, newSplit, 0, length); 74 | return newSplit; 75 | } 76 | } 77 | 78 | /** 79 | * Shortens the string to fit in the specified size. 80 | * @return the shortened string 81 | */ 82 | public static String trimMaxLength(String str, int length) { 83 | if (str.length() < length) 84 | return str; 85 | else if (length > 3) 86 | return str.substring(0, length); 87 | else 88 | throw new UnsupportedOperationException("Minimum length of 3 characters."); 89 | } 90 | 91 | /** 92 | * Shortens the string to fit in the specified size with an elipse "..." at the end. 93 | * @return the shortened string 94 | */ 95 | public static String maxLength(String str, int length) { 96 | if (str.length() < length) 97 | return str; 98 | else if (length > 3) 99 | return str.substring(0, length-3) + "..."; 100 | else 101 | throw new UnsupportedOperationException("Minimum length of 3 characters."); 102 | } 103 | 104 | public static boolean containsIgnoreCase(List arr, String str) { 105 | for (String s : arr) 106 | if (s.equalsIgnoreCase(str)) 107 | return true; 108 | return false; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/BukkitPermSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.permissions.PermissionAttachmentInfo; 5 | 6 | import com.palmergames.bukkit.towny.Towny; 7 | import com.palmergames.bukkit.towny.object.Resident; 8 | 9 | 10 | public class BukkitPermSource extends TownyPermissionSource { 11 | 12 | public BukkitPermSource(Towny towny) { 13 | this.plugin = towny; 14 | } 15 | 16 | @Override 17 | public String getPrefixSuffix(Resident resident, String node) { 18 | /* 19 | * Bukkit doesn't support prefix/suffix 20 | * so treat the same as bPerms 21 | */ 22 | 23 | Player player = plugin.getServer().getPlayer(resident.getName()); 24 | 25 | for (PermissionAttachmentInfo test: player.getEffectivePermissions()) { 26 | if (test.getPermission().startsWith(node+".")) { 27 | String[] split = test.getPermission().split("\\."); 28 | return split[split.length-1]; 29 | } 30 | } 31 | return ""; 32 | } 33 | 34 | /** 35 | * 36 | * @param playerName 37 | * @param node 38 | * @return -1 = can't find 39 | */ 40 | @Override 41 | public int getGroupPermissionIntNode(String playerName, String node) { 42 | /* 43 | * Bukkit doesn't support non boolean nodes 44 | * so treat the same as bPerms 45 | */ 46 | 47 | Player player = plugin.getServer().getPlayer(playerName); 48 | 49 | for (PermissionAttachmentInfo test: player.getEffectivePermissions()) { 50 | if (test.getPermission().startsWith(node+".")) { 51 | String[] split = test.getPermission().split("\\."); 52 | try { 53 | return Integer.parseInt(split[split.length-1]); 54 | } catch (NumberFormatException e) { 55 | } 56 | } 57 | } 58 | 59 | return -1; 60 | } 61 | 62 | /** 63 | * 64 | * @param playerName 65 | * @param node 66 | * @return empty = can't find 67 | */ 68 | @Override 69 | public String getPlayerPermissionStringNode(String playerName, String node) { 70 | /* 71 | * Bukkit doesn't support non boolean nodes 72 | * so treat the same as bPerms 73 | */ 74 | 75 | Player player = plugin.getServer().getPlayer(playerName); 76 | 77 | for (PermissionAttachmentInfo test: player.getEffectivePermissions()) { 78 | if (test.getPermission().startsWith(node+".")) { 79 | String[] split = test.getPermission().split("\\."); 80 | return split[split.length-1]; 81 | 82 | } 83 | } 84 | 85 | return ""; 86 | } 87 | 88 | 89 | /** hasPermission 90 | * 91 | * returns if a player has a certain permission node. 92 | * 93 | * @param player 94 | * @param node 95 | * @return true if Op or has the permission node. 96 | */ 97 | @Override 98 | public boolean hasPermission(Player player, String node) { 99 | 100 | if (player.isOp()) 101 | return true; 102 | 103 | final String[] parts = node.split("\\."); 104 | final StringBuilder builder = new StringBuilder(node.length()); 105 | for (String part : parts) { 106 | builder.append('*'); 107 | if (player.hasPermission("-" + builder.toString())) { 108 | return false; 109 | } 110 | if (player.hasPermission(builder.toString())) { 111 | return true; 112 | } 113 | builder.deleteCharAt(builder.length() - 1); 114 | builder.append(part).append('.'); 115 | } 116 | return player.hasPermission(node); 117 | //return player.hasPermission(node); 118 | } 119 | 120 | /** 121 | * Returns the players Group name. 122 | * 123 | * @param player 124 | * @return Empty string as bukkit doesn't support groups 125 | */ 126 | @Override 127 | public String getPlayerGroup(Player player) { 128 | 129 | //BukkitPermissions doesn't support groups. 130 | return ""; 131 | 132 | } 133 | 134 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/PermissionNodes.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | /** 4 | * @author ElgarL 5 | * 6 | */ 7 | public enum PermissionNodes { 8 | TOWNY_ADMIN("towny.admin"), 9 | CHEAT_BYPASS("towny.cheat.bypass"), 10 | TOWNY_TOP("towny.top"), 11 | TOWNY_TOWN_ALL("towny.town.*"), 12 | 13 | TOWNY_TOWN_NEW("towny.town.new"), 14 | TOWNY_TOWN_RESIDENT("towny.town.resident"), 15 | TOWNY_TOWN_DELETE("towny.town.delete"), 16 | TOWNY_TOWN_RENAME("towny.town.rename"), 17 | TOWNY_TOWN_CLAIM("towny.town.claim"), 18 | TOWNY_TOWN_CLAIM_OUTPOST("towny.town.claim.outpost"), 19 | TOWNY_TOWN_PLOT("towny.town.plot"), 20 | TOWNY_TOWN_PLOTTYPE("towny.town.plottype"), 21 | 22 | TOWNY_SPAWN_ALL("towny.town.spawn.*"), 23 | 24 | TOWNY_SPAWN_TOWN("towny.town.spawn.town"), 25 | TOWNY_SPAWN_NATION("towny.town.spawn.nation"), 26 | TOWNY_SPAWN_ALLY("towny.town.spawn.ally"), 27 | TOWNY_SPAWN_PUBLIC("towny.town.spawn.public"), 28 | 29 | TOWNY_TOGGLE_ALL("towny.town.toggle.*"), 30 | 31 | TOWNY_TOGGLE_PVP("towny.town.toggle.pvp"), 32 | TOWNY_TOGGLE_PUBLIC("towny.town.toggle.public"), 33 | TOWNY_TOGGLE_EXPLOSION("towny.town.toggle.explosions"), 34 | TOWNY_TOGGLE_FIRE("towny.town.toggle.fire"), 35 | TOWNY_TOGGLE_MOBS("towny.town.toggle.mobs"), 36 | TOWNY_TOGGLE_OPEN("towny.town.toggle.open"), 37 | 38 | TOWNY_NATION_ALL("towny.nation.*"), 39 | 40 | TOWNY_NATION_NEW("towny.nation.new"), 41 | TOWNY_NATION_DELETE("towny.nation.delete"), 42 | TOWNY_NATION_RENAME("towny.nation.rename"), 43 | TOWNY_NATION_GRANT_TITLES("towny.nation.grant-titles"), 44 | 45 | TOWNY_WILD_ALL("towny.wild.*"), 46 | 47 | TOWNY_WILD_BUILD("towny.wild.build"), 48 | TOWNY_WILD_DESTROY("towny.wild.destroy"), 49 | TOWNY_WILD_SWITCH("towny.wild.switch"), 50 | TOWNY_WILD_ITEM_USE("towny.wild.item_use"), 51 | 52 | TOWNY_WILD_BLOCK_ALL("towny.wild.block.*"), 53 | 54 | TOWNY_WILD_BLOCK_BUILD("towny.wild.block.*.build"), 55 | TOWNY_WILD_BLOCK_DESTROY("towny.wild.block.*.destroy"), 56 | TOWNY_WILD_BLOCK_SWITCH("towny.wild.block.*.switch"), 57 | TOWNY_WILD_BLOCK_ITEM_USE("towny.wild.block.*.item_use"), 58 | 59 | TOWNY_CLAIMED_ALL("towny.claimed.*"), 60 | 61 | TOWNY_CLAIMED_BUILD("towny.claimed.build"), 62 | TOWNY_CLAIMED_DESTROY("towny.claimed.destroy"), 63 | TOWNY_CLAIMED_SWITCH("towny.claimed.switch"), 64 | TOWNY_CLAIMED_ITEM_USE("towny.claimed.item_use"), 65 | 66 | TOWNY_CLAIMED_ALL_BLOCK("towny.claimed.alltown.block.*"), 67 | 68 | TOWNY_CLAIMED_ALL_BLOCK_BUILD("towny.claimed.alltown.block.*.build"), 69 | TOWNY_CLAIMED_ALL_BLOCK_DESTROY("towny.claimed.alltown.block.*.destroy"), 70 | TOWNY_CLAIMED_ALL_BLOCK_SWITCH("towny.claimed.alltown.block.*.switch"), 71 | TOWNY_CLAIMED_ALL_BLOCK_ITEM_USE("towny.claimed.alltown.block.*.item_use"), 72 | 73 | TOWNY_CLAIMED_OWNTOWN_BLOCK("towny.claimed.owntown.block.*"), 74 | 75 | TOWNY_CLAIMED_OWNTOWN_BLOCK_BUILD("towny.claimed.owntown.block.*.build"), 76 | TOWNY_CLAIMED_OWNTOWN_BLOCK_DESTROY("towny.claimed.owntown.block.*.destroy"), 77 | TOWNY_CLAIMED_OWNTOWN_BLOCK_SWITCH("towny.claimed.owntown.block.*.switch"), 78 | TOWNY_CLAIMED_OWNTOWN_BLOCK_ITEM_USE("towny.claimed.owntown.block.*.item_use"), 79 | 80 | TOWNY_CHAT_ALL("towny.chat.*"), 81 | 82 | TOWNY_CHAT_TOWN("towny.chat.town"), 83 | TOWNY_CHAT_NATION("towny.chat.nation"), 84 | TOWNY_CHAT_ADMIN("towny.chat.admin"), 85 | TOWNY_CHAT_MOD("towny.chat.mod"), 86 | TOWNY_CHAT_GLOBAL("towny.chat.global"), 87 | TOWNY_CHAT_SPY("towny.chat.spy"), 88 | 89 | // Info nodes 90 | 91 | TOWNY_DEFAULT_MODES("towny_default_modes"), 92 | TOWNY_MAX_PLOTS("towny_maxplots"),; 93 | 94 | private String value; 95 | 96 | /** 97 | * Constructor 98 | * @param permission 99 | */ 100 | private PermissionNodes(String permission) { 101 | this.value = permission; 102 | } 103 | 104 | /** 105 | * Retrieves the permission node 106 | * @return The permission node 107 | */ 108 | public String getNode() { 109 | return value; 110 | } 111 | /** 112 | * Retrieves the permission node 113 | * replacing the character * 114 | * @return The permission node 115 | */ 116 | public String getNode(String replace) { 117 | return value.replace("*", replace); 118 | } 119 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/bPermsSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | 4 | import org.bukkit.entity.Player; 5 | import org.bukkit.plugin.Plugin; 6 | 7 | import de.bananaco.permissions.Permissions; 8 | import de.bananaco.permissions.info.InfoReader; 9 | import de.bananaco.permissions.interfaces.PermissionSet; 10 | 11 | import com.palmergames.bukkit.towny.Towny; 12 | import com.palmergames.bukkit.towny.TownySettings; 13 | import com.palmergames.bukkit.towny.object.Resident; 14 | 15 | 16 | public class bPermsSource extends TownyPermissionSource { 17 | 18 | public bPermsSource(Towny towny, Plugin test) { 19 | //this.bPermissions = (Permissions)test; 20 | this.plugin = towny; 21 | } 22 | 23 | /** getPermissionNode 24 | * 25 | * returns the specified prefix/suffix nodes from permissionsEX 26 | * 27 | * @param resident 28 | * @param node 29 | * @return String of the prefix/suffix 30 | */ 31 | @Override 32 | public String getPrefixSuffix(Resident resident, String node) { 33 | 34 | String group = "", user = ""; 35 | Player player = plugin.getServer().getPlayer(resident.getName()); 36 | 37 | //PermissionSet bPermPM = Permissions.getWorldPermissionsManager().getPermissionSet(player.getWorld()); 38 | InfoReader bPermIR = Permissions.getInfoReader(); 39 | 40 | if (node == "prefix") { 41 | group = bPermIR.getGroupPrefix(getPlayerGroup(player), player.getWorld().getName()); 42 | user = bPermIR.getPrefix(player); 43 | } else if (node == "suffix") { 44 | group = bPermIR.getGroupSuffix(getPlayerGroup(player), player.getWorld().getName()); 45 | user = bPermIR.getSuffix(player); 46 | } 47 | if (group == null) group = ""; 48 | if (user == null) user = ""; 49 | 50 | if (!group.equals(user)) 51 | user = group + user; 52 | user = TownySettings.parseSingleLineString(user); 53 | 54 | return user; 55 | 56 | } 57 | 58 | /** 59 | * 60 | * @param playerName 61 | * @param node 62 | * @return -1 = can't find 63 | */ 64 | @Override 65 | public int getGroupPermissionIntNode(String playerName, String node) { 66 | Player player = plugin.getServer().getPlayer(playerName); 67 | 68 | InfoReader bPermIR = Permissions.getInfoReader(); 69 | 70 | String result = bPermIR.getValue(player, node); 71 | 72 | try { 73 | return Integer.parseInt(result); 74 | } catch (NumberFormatException e) { 75 | return -1; 76 | } 77 | 78 | } 79 | 80 | /** 81 | * 82 | * @param playerName 83 | * @param node 84 | * @return empty = can't find 85 | */ 86 | @Override 87 | public String getPlayerPermissionStringNode(String playerName, String node) { 88 | Player player = plugin.getServer().getPlayer(playerName); 89 | 90 | InfoReader bPermIR = Permissions.getInfoReader(); 91 | 92 | String result = bPermIR.getValue(player, node); 93 | 94 | if (result == null) 95 | return ""; 96 | 97 | return result; 98 | 99 | } 100 | 101 | /** hasPermission 102 | * 103 | * returns if a player has a certain permission node. 104 | * 105 | * @param player 106 | * @param node 107 | * @return true is Op or has the permission node 108 | */ 109 | @Override 110 | public boolean hasPermission(Player player, String node) { 111 | //PermissionSet bPermPM = Permissions.getWorldPermissionsManager().getPermissionSet(player.getWorld()); 112 | 113 | if (player.isOp()) 114 | return true; 115 | 116 | final String[] parts = node.split("\\."); 117 | final StringBuilder builder = new StringBuilder(node.length()); 118 | for (String part : parts) { 119 | builder.append('*'); 120 | if (player.hasPermission("-" + builder.toString())) { 121 | return false; 122 | } 123 | if (player.hasPermission(builder.toString())) { 124 | return true; 125 | } 126 | builder.deleteCharAt(builder.length() - 1); 127 | builder.append(part).append('.'); 128 | } 129 | return player.hasPermission(node); 130 | //return player.hasPermission(node); 131 | } 132 | 133 | /** 134 | * Returns the players Group name. 135 | * 136 | * @param player 137 | * @return String name of this players group. 138 | */ 139 | @Override 140 | public String getPlayerGroup(Player player) { 141 | 142 | PermissionSet bPermPM = Permissions.getWorldPermissionsManager().getPermissionSet(player.getWorld()); 143 | 144 | return bPermPM.getGroups(player).get(0); 145 | 146 | } 147 | 148 | 149 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/TownyWarConfig.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar; 2 | 3 | import java.util.Set; 4 | 5 | import org.bukkit.DyeColor; 6 | import org.bukkit.Material; 7 | 8 | import com.palmergames.bukkit.config.ConfigNodes; 9 | import com.palmergames.bukkit.towny.TownySettings; 10 | import com.palmergames.bukkit.util.TimeTools; 11 | 12 | public class TownyWarConfig { 13 | public static final DyeColor[] woolColors = new DyeColor[] { 14 | DyeColor.LIME, 15 | DyeColor.GREEN, 16 | DyeColor.BLUE, 17 | DyeColor.CYAN, 18 | DyeColor.LIGHT_BLUE, 19 | DyeColor.SILVER, 20 | DyeColor.WHITE, 21 | DyeColor.PINK, 22 | DyeColor.ORANGE, 23 | DyeColor.RED 24 | }; 25 | 26 | private static Material flagBaseMaterial = null; 27 | private static Material flagLightMaterial = null; 28 | private static Material beaconWireFrameMaterial = null; 29 | 30 | private static Set editableMaterialsInWarZone = null; 31 | 32 | public static boolean isAffectedMaterial(Material material) { 33 | return material == Material.WOOL 34 | || material == getFlagBaseMaterial() 35 | || material == getFlagLightMaterial() 36 | || material == getBeaconWireFrameMaterial(); 37 | } 38 | 39 | public static String parseSingleLineString(String str) { 40 | return str.replaceAll("&", "\u00A7"); 41 | } 42 | 43 | public static DyeColor[] getWoolColors() { 44 | return woolColors; 45 | } 46 | 47 | public static boolean isAllowingAttacks() { 48 | return TownySettings.getBoolean(ConfigNodes.WAR_ENEMY_ALLOW_ATTACKS); 49 | } 50 | 51 | public static long getFlagWaitingTime() { 52 | return TimeTools.getMillis(TownySettings.getString(ConfigNodes.WAR_ENEMY_FLAG_WAITING_TIME)); 53 | } 54 | 55 | public static long getTimeBetweenFlagColorChange() { 56 | return getFlagWaitingTime() / getWoolColors().length; 57 | } 58 | 59 | public static boolean isDrawingBeacon() { 60 | return TownySettings.getBoolean(ConfigNodes.WAR_ENEMY_BEACON_DRAW); 61 | } 62 | 63 | public static int getMaxActiveFlagsPerPerson() { 64 | return TownySettings.getInt(ConfigNodes.WAR_ENEMY_MAX_ACTIVE_FLAGS_PER_PLAYER); 65 | } 66 | 67 | public static Material getFlagBaseMaterial() { 68 | return flagBaseMaterial; 69 | } 70 | 71 | public static Material getFlagLightMaterial() { 72 | return flagLightMaterial; 73 | } 74 | 75 | public static Material getBeaconWireFrameMaterial() { 76 | return beaconWireFrameMaterial; 77 | } 78 | 79 | public static int getBeaconRadius() { 80 | return TownySettings.getInt(ConfigNodes.WAR_ENEMY_BEACON_RADIUS); 81 | } 82 | 83 | public static int getBeaconSize() { 84 | return getBeaconRadius() * 2 - 1; 85 | } 86 | 87 | public static void setFlagBaseMaterial(Material flagBaseMaterial) { 88 | TownyWarConfig.flagBaseMaterial = flagBaseMaterial; 89 | } 90 | 91 | public static void setFlagLightMaterial(Material flagLightMaterial) { 92 | TownyWarConfig.flagLightMaterial = flagLightMaterial; 93 | } 94 | 95 | public static void setBeaconWireFrameMaterial(Material beaconWireFrameMaterial) { 96 | TownyWarConfig.beaconWireFrameMaterial = beaconWireFrameMaterial; 97 | } 98 | 99 | 100 | public static int getMinPlayersOnlineInTownForWar() { 101 | return TownySettings.getInt(ConfigNodes.WAR_ENEMY_MIN_PLAYERS_ONLINE_IN_TOWN); 102 | } 103 | 104 | public static int getMinPlayersOnlineInNationForWar() { 105 | return TownySettings.getInt(ConfigNodes.WAR_ENEMY_MIN_PLAYERS_ONLINE_IN_NATION); 106 | } 107 | 108 | public static void setEditableMaterialsInWarZone(Set editableMaterialsInWarZone) { 109 | TownyWarConfig.editableMaterialsInWarZone = editableMaterialsInWarZone; 110 | } 111 | 112 | public static boolean isEditableMaterialInWarZone(Material material) { 113 | return TownyWarConfig.editableMaterialsInWarZone.contains(material); 114 | } 115 | 116 | public static boolean isAllowingSwitchesInWarZone() { 117 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_SWITCH); 118 | } 119 | 120 | public static boolean isAllowingFireInWarZone() { 121 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_FIRE); 122 | } 123 | 124 | public static boolean isAllowingItemUseInWarZone() { 125 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_ITEM_USE); 126 | } 127 | 128 | public static boolean isAllowingExplosionsInWarZone() { 129 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_EXPLOSIONS); 130 | } 131 | 132 | public static boolean explosionsBreakBlocksInWarZone() { 133 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_EXPLOSIONS_BREAK_BLOCKS); 134 | } 135 | 136 | public static boolean regenBlocksAfterExplosionInWarZone() { 137 | return TownySettings.getBoolean(ConfigNodes.WAR_WARZONE_EXPLOSIONS_REGEN_BLOCKS); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/Perms3Source.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | import org.bukkit.entity.Player; 4 | import org.bukkit.plugin.Plugin; 5 | 6 | import com.nijiko.permissions.PermissionHandler; 7 | import com.nijikokun.bukkit.Permissions.Permissions; 8 | import com.palmergames.bukkit.towny.Towny; 9 | import com.palmergames.bukkit.towny.TownySettings; 10 | import com.palmergames.bukkit.towny.object.Resident; 11 | 12 | 13 | public class Perms3Source extends TownyPermissionSource { 14 | 15 | public Perms3Source(Towny towny, Plugin test) { 16 | this.permissions = (Permissions)test; 17 | this.plugin = towny; 18 | } 19 | 20 | /** getPermissionNode 21 | * 22 | * returns the specified prefix/suffix nodes from permissions 23 | * 24 | * @param resident 25 | * @param node 26 | * @return String of the prefix/Suffix for this player. 27 | */ 28 | @Override 29 | // Suppression is to clear warnings while retaining permissions 2.7 compatibility 30 | public String getPrefixSuffix(Resident resident, String node) { 31 | 32 | String group = "", user = ""; 33 | Player player = plugin.getServer().getPlayer(resident.getName()); 34 | 35 | //sendDebugMsg(" Permissions installed."); 36 | PermissionHandler handler = permissions.getHandler(); 37 | 38 | if (node == "prefix") { 39 | group = handler.getGroupPrefix(player.getWorld().getName(), handler.getGroup(player.getWorld().getName(), player.getName())); 40 | //user = handler.getUserPrefix(player.getWorld().getName(), player.getName()); 41 | } else if (node == "suffix") { 42 | group = handler.getGroupSuffix(player.getWorld().getName(), handler.getGroup(player.getWorld().getName(), player.getName())); 43 | //user = handler.getUserSuffix(player.getWorld().getName(), player.getName()); 44 | } 45 | 46 | if (!group.equals(user)) 47 | user = group + user; 48 | user = TownySettings.parseSingleLineString(user); 49 | 50 | return user; 51 | 52 | } 53 | 54 | /** 55 | * 56 | * @param playerName 57 | * @param node 58 | * @return -1 = can't find 59 | */ 60 | @Override 61 | // Suppression is to clear warnings while retaining permissions 2.7 compatibility 62 | public int getGroupPermissionIntNode(String playerName, String node) { 63 | Player player = plugin.getServer().getPlayer(playerName); 64 | String worldName = player.getWorld().getName(); 65 | String groupName; 66 | 67 | try { 68 | PermissionHandler handler = permissions.getHandler(); 69 | groupName = handler.getGroup(worldName, playerName); 70 | 71 | return handler.getGroupPermissionInteger(worldName, groupName, node); 72 | } catch (Exception e) { 73 | // Ignore UnsupportedOperationException on certain Permission APIs 74 | } 75 | 76 | return -1; 77 | } 78 | 79 | /** 80 | * 81 | * @param playerName 82 | * @param node 83 | * @return empty = can't find 84 | */ 85 | @Override 86 | // Suppression is to clear warnings while retaining permissions 2.7 compatibility 87 | public String getPlayerPermissionStringNode(String playerName, String node) { 88 | Player player = plugin.getServer().getPlayer(playerName); 89 | String worldName = player.getWorld().getName(); 90 | String groupName; 91 | 92 | try { 93 | PermissionHandler handler = permissions.getHandler(); 94 | groupName = handler.getGroup(worldName, playerName); 95 | String perm = handler.getGroupPermissionString(worldName, groupName, node); 96 | 97 | if (perm != null) 98 | return perm; 99 | } catch (Exception e) { 100 | // Ignore UnsupportedOperationException on certain Permission APIs 101 | } 102 | 103 | return ""; 104 | } 105 | 106 | /** hasPermission 107 | * 108 | * returns if a player has a certain permission node. 109 | * 110 | * @param player 111 | * @param node 112 | * @return true is Op or has the permission node 113 | */ 114 | @Override 115 | public boolean hasPermission(Player player, String node) { 116 | 117 | if (player.isOp()) 118 | return true; 119 | 120 | PermissionHandler handler = permissions.getHandler(); 121 | return handler.permission(player, node); 122 | } 123 | 124 | 125 | /** 126 | * Returns the players Group name. 127 | * 128 | * @param player 129 | * @return Name of this players group. 130 | */ 131 | @Override 132 | public String getPlayerGroup(Player player) { 133 | 134 | PermissionHandler handler = permissions.getHandler(); 135 | return handler.getGroup(player.getWorld().getName(), player.getName()); 136 | 137 | } 138 | 139 | } -------------------------------------------------------------------------------- /src/ToDo.txt: -------------------------------------------------------------------------------- 1 | TODO: 2 | Update cache when adding/removing people 3 | Ability to make NPC Residents profiles (not actual human entities). /townyadmin set mayor [town] npc 4 | Remember outposts coordinated. Charge extra tax on them. Allow for outpost teleporting. 5 | Admins can moderate town/nation channels ingame. 6 | Delay for changing between PvP and Non-PvP. 7 | Require x residents to start a town. 8 | Buy certain sizes of towns. 9 | Mob removal by town. Ingame command. 10 | Town set mobremoval on -> pay cost. 11 | if not one time payment, every day = charge. 12 | 13 | Secondary: 14 | Commenting 15 | Replace getDataSource() with a manager class to allow multiple save formats at once. 16 | Make the formatting/wording for [nation] .. [nation] etc, better. 17 | Chat: 18 | Town/nation name 19 | Friends show up differently. 20 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-27#post-132597 21 | NewTown -> Min dist from claimed townblock. 22 | Re-register a player after res delete. 23 | Claim circle [radius]. 24 | Managed to claim 5 out of the 16 selected (x1,z1) .. (x2,z2). 25 | On login, see if there's been any events. Make command: /town log [page] to see messages. 26 | Function to cleanup non linked files in database. 27 | Server tax on town/nation per residents it contains. Don't delete town if it can't pay. 28 | Own an area, but don't force permissions on it. 29 | 30 | Cool Concepts: 31 | In the wild, users who've registered less than X time are exempt to permissions. 32 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-34-resident-town-nation-hierarchy-grid-based-protection.3358/page-12#post-73637 33 | In the wild, allow people to mine underneath height of x. 34 | 35 | Probably need TODO something: 36 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-34-resident-town-nation-hierarchy-grid-based-protection.3358/page-14#post-81114 37 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-44-resident-town-nation-hierarchy-grid-based-protection.3358/page-18#post-92835 38 | 39 | 40 | Bugs: 41 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-34-resident-town-nation-hierarchy-grid-based-protection.3358/page-12#post-74896 42 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-46-resident-town-nation-hierarchy-grid-based-protection.3358/page-22#post-109451 43 | AG_Elias: I am having an issue with Towny. It seems to not pass events on to Craftbook if the event occurs in a town. 44 | 45 | Placing halfsteps on other halfsteps of a diffent type will place the step regardless of cancelling the event. Placing slabs of the same type (not smooth type) will cancel the event, but turn the bottom to smooth slab. When placing indirectly (block on top), the second effect happens (changing to smooth), but the first effect does not happen. 46 | http://www.youtube.com/watch?v=WPoozI4HJWE 47 | Towns being randomly deleted 48 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-24#post-121274 49 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-27#post-130832 50 | Town files resetting: 51 | Realmz 52 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-26#post-128932 53 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-54-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-29#post-137119 54 | Possibly?: 55 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-54-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-30#post-145235 56 | Deleting a resident leaves it's pointer in Town.getResidents(). 57 | Leaving town - Plot bug 58 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-27#post-130470 59 | Towns remaining after deletion. 60 | Essentials cooldown etc. 61 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-26#post-129664 62 | Protection issues. 63 | Destroy was fine, but player was able to build. 64 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-26#post-129321 65 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-52-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-26#post-129035 66 | I'm having some trouble with the autoupdating map and the claim as you walk thingies... Not working. 67 | -> Not detecting onChunk Moved? 68 | Permissions bug: 69 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-54-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-29#post-137988 70 | 71 | Charged death_price multiple times when you die. 72 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-54-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-29#post-138787 73 | http://forums.bukkit.org/threads/sec-fun-info-towny-v0-54-resident-town-nation-hierarchy-grid-based-protection-531.3358/page-30#post-145146 74 | Kick from town (due to taxes), owned plots go up for sale. When re-added, plot is no longer for sale. 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/PlayerCache.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import org.bukkit.Location; 4 | import org.bukkit.entity.Player; 5 | 6 | import com.palmergames.bukkit.towny.object.Coord; 7 | import com.palmergames.bukkit.towny.object.TownyWorld; 8 | import com.palmergames.bukkit.towny.object.WorldCoord; 9 | import com.palmergames.bukkit.towny.object.TownyPermission.ActionType; 10 | 11 | public class PlayerCache { 12 | private WorldCoord lastTownBlock; 13 | private Boolean buildPermission, destroyPermission, switchPermission, itemUsePermission; 14 | private String blockErrMsg; 15 | private Location lastLocation; 16 | //TODO: cache last entity attacked 17 | 18 | public PlayerCache(TownyWorld world, Player player) { 19 | this(new WorldCoord(world, Coord.parseCoord(player))); 20 | setLastLocation(player.getLocation()); 21 | } 22 | 23 | public PlayerCache(WorldCoord lastTownBlock) { 24 | this.setLastTownBlock(lastTownBlock); 25 | } 26 | 27 | /** 28 | * Update the cache with new coordinates. Reset the other cached permissions. 29 | * @param lastTownBlock 30 | */ 31 | 32 | public void setLastTownBlock(WorldCoord lastTownBlock) { 33 | reset(); 34 | this.lastTownBlock = lastTownBlock; 35 | } 36 | 37 | public WorldCoord getLastTownBlock() { 38 | return lastTownBlock; 39 | } 40 | 41 | public boolean getCachePermission(ActionType action) throws NullPointerException { 42 | 43 | switch(action){ 44 | 45 | case BUILD: // BUILD 46 | if (buildPermission == null) 47 | throw new NullPointerException(); 48 | else 49 | return buildPermission; 50 | 51 | case DESTROY: // DESTROY 52 | if (destroyPermission == null) 53 | throw new NullPointerException(); 54 | else 55 | return destroyPermission; 56 | 57 | case SWITCH: // SWITCH 58 | if (switchPermission == null) 59 | throw new NullPointerException(); 60 | else 61 | return switchPermission; 62 | 63 | case ITEM_USE: // ITEM_USE 64 | if (itemUsePermission == null) 65 | throw new NullPointerException(); 66 | else 67 | return itemUsePermission; 68 | 69 | default: 70 | throw new NullPointerException(); 71 | 72 | } 73 | 74 | } 75 | 76 | public void setBuildPermission(boolean buildPermission) { 77 | this.buildPermission = buildPermission; 78 | } 79 | 80 | public boolean getBuildPermission() throws NullPointerException { 81 | if (buildPermission == null) 82 | throw new NullPointerException(); 83 | else 84 | return buildPermission; 85 | } 86 | 87 | public void setDestroyPermission(boolean destroyPermission) { 88 | this.destroyPermission = destroyPermission; 89 | } 90 | 91 | public boolean getDestroyPermission() throws NullPointerException { 92 | if (destroyPermission == null) 93 | throw new NullPointerException(); 94 | else 95 | return destroyPermission; 96 | } 97 | 98 | public void setSwitchPermission(boolean switchPermission) { 99 | this.switchPermission = switchPermission; 100 | } 101 | 102 | public boolean getSwitchPermission() throws NullPointerException { 103 | if (switchPermission == null) 104 | throw new NullPointerException(); 105 | else 106 | return switchPermission; 107 | } 108 | 109 | public boolean updateCoord(WorldCoord pos) { 110 | if (!getLastTownBlock().equals(pos)) { 111 | setLastTownBlock(pos); 112 | return true; 113 | } else 114 | return false; 115 | } 116 | 117 | private void reset() { 118 | lastTownBlock = null; 119 | buildPermission = null; 120 | destroyPermission = null; 121 | townBlockStatus = null; 122 | switchPermission = null; 123 | itemUsePermission = null; 124 | blockErrMsg = null; 125 | } 126 | 127 | public enum TownBlockStatus { 128 | UNKOWN, 129 | NOT_REGISTERED, 130 | OFF_WORLD, // In a world untouched by towny. 131 | ADMIN, 132 | UNCLAIMED_ZONE, 133 | LOCKED, 134 | WARZONE, 135 | OUTSIDER, 136 | PLOT_OWNER, 137 | PLOT_FRIEND, 138 | PLOT_ALLY, 139 | TOWN_OWNER, 140 | TOWN_RESIDENT, 141 | TOWN_ALLY, 142 | ENEMY 143 | }; 144 | 145 | private TownBlockStatus townBlockStatus = TownBlockStatus.UNKOWN; 146 | 147 | public void setStatus(TownBlockStatus townBlockStatus) { 148 | this.townBlockStatus = townBlockStatus; 149 | } 150 | 151 | public TownBlockStatus getStatus() throws NullPointerException { 152 | if (townBlockStatus == null) 153 | throw new NullPointerException(); 154 | else 155 | return townBlockStatus; 156 | } 157 | 158 | public void setBlockErrMsg(String blockErrMsg) { 159 | this.blockErrMsg = blockErrMsg; 160 | } 161 | 162 | public String getBlockErrMsg() { 163 | String temp = blockErrMsg; 164 | setBlockErrMsg(null); // Delete error msg after reading it. 165 | return temp; 166 | } 167 | 168 | public boolean hasBlockErrMsg() { 169 | return blockErrMsg != null; 170 | } 171 | 172 | public void setItemUsePermission(Boolean itemUsePermission) { 173 | this.itemUsePermission = itemUsePermission; 174 | } 175 | 176 | public Boolean getItemUsePermission() throws NullPointerException { 177 | if (itemUsePermission == null) 178 | throw new NullPointerException(); 179 | else 180 | return itemUsePermission; 181 | } 182 | 183 | public void setLastLocation(Location lastLocation) { 184 | this.lastLocation = lastLocation.clone(); 185 | } 186 | 187 | public Location getLastLocation() throws NullPointerException { 188 | if (lastLocation == null) 189 | throw new NullPointerException(); 190 | else 191 | return lastLocation; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/CellUnderAttack.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.DyeColor; 7 | import org.bukkit.Material; 8 | import org.bukkit.World; 9 | import org.bukkit.block.Block; 10 | 11 | import com.palmergames.bukkit.towny.object.Coord; 12 | 13 | public class CellUnderAttack extends Cell { 14 | private String nameOfFlagOwner; 15 | private List beaconFlagBlocks; 16 | private List beaconWireframeBlocks; 17 | private Block flagBaseBlock, flagBlock, flagLightBlock; 18 | private int flagColorId; 19 | private CellAttackThread thread; 20 | 21 | public CellUnderAttack(String nameOfFlagOwner, Block flagBaseBlock) { 22 | super(flagBaseBlock.getLocation()); 23 | this.nameOfFlagOwner = nameOfFlagOwner; 24 | this.flagBaseBlock = flagBaseBlock; 25 | this.flagColorId = 0; 26 | this.thread = new CellAttackThread(this); 27 | 28 | World world = flagBaseBlock.getWorld(); 29 | this.flagBlock = world.getBlockAt(flagBaseBlock.getX(), flagBaseBlock.getY() + 1, flagBaseBlock.getZ()); 30 | this.flagLightBlock = world.getBlockAt(flagBaseBlock.getX(), flagBaseBlock.getY() + 2, flagBaseBlock.getZ()); 31 | } 32 | 33 | public void loadBeacon() { 34 | beaconFlagBlocks = new ArrayList(); 35 | beaconWireframeBlocks = new ArrayList(); 36 | 37 | if (!TownyWarConfig.isDrawingBeacon()) 38 | return; 39 | 40 | int beaconSize = TownyWarConfig.getBeaconSize(); 41 | if (Coord.getCellSize() < beaconSize) 42 | return; 43 | 44 | Block minBlock = getBeaconMinBlock(getFlagBaseBlock().getWorld()); 45 | if (flagBaseBlock.getY() + 4 > minBlock.getY()) 46 | return; 47 | 48 | int outerEdge = beaconSize - 1; 49 | for (int y = 0; y < beaconSize; y++) { 50 | for (int z = 0; z < beaconSize; z++) { 51 | for (int x = 0; x < beaconSize; x++) { 52 | Block block = flagBaseBlock.getWorld().getBlockAt(minBlock.getX() + x, minBlock.getY() + y, minBlock.getZ() + z); 53 | if (block.isEmpty()) { 54 | int edgeCount = getEdgeCount(x, y, z, outerEdge); 55 | if (edgeCount == 1) { 56 | beaconFlagBlocks.add(block); 57 | } else if (edgeCount > 1) { 58 | beaconWireframeBlocks.add(block); 59 | } 60 | } 61 | } 62 | } 63 | } 64 | } 65 | 66 | private int getEdgeCount(int x, int y, int z, int outerEdge) { 67 | return (zeroOr(x, outerEdge) ? 1 : 0) + (zeroOr(y, outerEdge) ? 1 : 0) + (zeroOr(z, outerEdge) ? 1 : 0); 68 | } 69 | 70 | private boolean zeroOr(int n, int max) { 71 | return n == 0 || n == max; 72 | } 73 | 74 | private Block getBeaconMinBlock(World world) { 75 | int middle = (int) Math.floor(Coord.getCellSize() / 2.0); 76 | int radiusCenterExpansion = TownyWarConfig.getBeaconRadius() - 1; 77 | int fromCorner = middle - radiusCenterExpansion; 78 | int maxY = world.getMaxHeight(); 79 | 80 | int x = (getX() * Coord.getCellSize()) + fromCorner; 81 | int y = maxY - TownyWarConfig.getBeaconSize(); 82 | int z = (getZ() * Coord.getCellSize()) + fromCorner; 83 | 84 | return world.getBlockAt(x, y, z); 85 | } 86 | 87 | public Block getFlagBaseBlock() { 88 | return flagBaseBlock; 89 | } 90 | 91 | public String getNameOfFlagOwner() { 92 | return nameOfFlagOwner; 93 | } 94 | 95 | public boolean hasEnded() { 96 | return flagColorId >= TownyWarConfig.getWoolColors().length; 97 | } 98 | 99 | public void changeFlag() { 100 | flagColorId += 1; 101 | updateFlag(); 102 | } 103 | 104 | public void drawFlag() { 105 | loadBeacon(); 106 | 107 | flagBaseBlock.setType(TownyWarConfig.getFlagBaseMaterial()); 108 | updateFlag(); 109 | flagLightBlock.setType(TownyWarConfig.getFlagLightMaterial()); 110 | for (Block block : beaconWireframeBlocks) 111 | block.setType(TownyWarConfig.getBeaconWireFrameMaterial()); 112 | } 113 | 114 | public void updateFlag() { 115 | DyeColor[] woolColors = TownyWarConfig.getWoolColors(); 116 | if (flagColorId < woolColors.length) { 117 | //System.out.println(String.format("Flag at %s turned %s.", getCellString(), woolColors[flagColorId].toString())); 118 | int woolId = Material.WOOL.getId(); 119 | byte woolData = woolColors[flagColorId].getData(); 120 | 121 | flagBlock.setTypeIdAndData(woolId, woolData, true); 122 | for (Block block : beaconFlagBlocks) 123 | block.setTypeIdAndData(woolId, woolData, true); 124 | } 125 | } 126 | 127 | public void destroyFlag() { 128 | flagLightBlock.setType(Material.AIR); 129 | flagBlock.setType(Material.AIR); 130 | flagBaseBlock.setType(Material.AIR); 131 | for (Block block : beaconFlagBlocks) 132 | block.setType(Material.AIR); 133 | for (Block block : beaconWireframeBlocks) 134 | block.setType(Material.AIR); 135 | } 136 | 137 | public void begin() { 138 | this.thread.start(); 139 | } 140 | 141 | public void cancel() { 142 | this.thread.setRunning(false); 143 | destroyFlag(); 144 | } 145 | 146 | public String getCellString() { 147 | return String.format("%s (%d, %d)", getWorldName(), getX(), getZ()); 148 | } 149 | 150 | public boolean isFlagLight(Block block) { 151 | return this.flagLightBlock.equals(block); 152 | } 153 | 154 | public boolean isFlag(Block block) { 155 | return this.flagBlock.equals(block); 156 | } 157 | 158 | public boolean isFlagBase(Block block) { 159 | return this.flagBaseBlock.equals(block); 160 | } 161 | 162 | public boolean isPartOfBeacon(Block block) { 163 | return beaconFlagBlocks.contains(block) || beaconWireframeBlocks.contains(block); 164 | } 165 | 166 | public boolean isUneditableBlock(Block block) { 167 | return isPartOfBeacon(block) || isFlagBase(block) || isFlagLight(block); 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownyRegenAPI.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Hashtable; 5 | import java.util.List; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.Chunk; 9 | import org.bukkit.ChunkSnapshot; 10 | import org.bukkit.World; 11 | 12 | import com.palmergames.bukkit.towny.TownyMessaging; 13 | import com.palmergames.bukkit.towny.TownySettings; 14 | import com.palmergames.bukkit.util.MinecraftTools; 15 | 16 | 17 | 18 | /** 19 | * @author ElgarL 20 | * 21 | */ 22 | public class TownyRegenAPI extends TownyUniverse { 23 | 24 | // table containing snapshot data of active reversions. 25 | private static Hashtable PlotChunks = new Hashtable(); 26 | 27 | // A list of worldCoords which are needing snapshots 28 | private static List worldCoords = new ArrayList(); 29 | 30 | /** 31 | * Add a TownBlocks WorldCoord for a snapshot to be taken. 32 | * 33 | * @param worldCoord 34 | */ 35 | public static void addWorldCoord(WorldCoord worldCoord) { 36 | if (!worldCoords.contains(worldCoord)) 37 | worldCoords.add(worldCoord); 38 | } 39 | /** 40 | * @return true if there are any TownBlocks to be processed. 41 | */ 42 | public static boolean hasWorldCoords() { 43 | return worldCoords.size() != 0; 44 | } 45 | /** 46 | * @return First WorldCoord to be processed. 47 | */ 48 | public static WorldCoord getWorldCoord() { 49 | if (!worldCoords.isEmpty()) { 50 | WorldCoord wc = worldCoords.get(0); 51 | worldCoords.remove(0); 52 | return wc; 53 | } 54 | return null; 55 | } 56 | 57 | /** 58 | * @return the plotChunks which are being processed 59 | */ 60 | public static Hashtable getPlotChunks() { 61 | return PlotChunks; 62 | } 63 | /** 64 | * @return true if there are any chunks being processed. 65 | */ 66 | public static boolean hasPlotChunks() { 67 | return !PlotChunks.isEmpty(); 68 | } 69 | 70 | /** 71 | * @param plotChunks the plotChunks to set 72 | */ 73 | public static void setPlotChunks(Hashtable plotChunks) { 74 | PlotChunks = plotChunks; 75 | } 76 | 77 | /** 78 | * Removes a Plot Chunk from the regeneration Hashtable 79 | * 80 | * @param plotChunk 81 | */ 82 | public static void deletePlotChunk(PlotBlockData plotChunk) { 83 | if (PlotChunks.containsKey(getPlotKey(plotChunk))) { 84 | PlotChunks.remove(getPlotKey(plotChunk)); 85 | TownyUniverse.getDataSource().saveRegenList(); 86 | } 87 | } 88 | 89 | /** 90 | * Adds a Plot Chunk to the regeneration Hashtable 91 | * 92 | * @param plotChunk 93 | * @param save 94 | */ 95 | public static void addPlotChunk(PlotBlockData plotChunk, boolean save) { 96 | if (!PlotChunks.containsKey(getPlotKey(plotChunk))) { 97 | //plotChunk.initialize(); 98 | PlotChunks.put(getPlotKey(plotChunk), plotChunk); 99 | if (save) 100 | TownyUniverse.getDataSource().saveRegenList(); 101 | } 102 | } 103 | /** 104 | * Saves a Plot Chunk snapshot to the datasource 105 | * 106 | * @param plotChunk 107 | */ 108 | public static void addPlotChunkSnapshot(PlotBlockData plotChunk) { 109 | if (TownyUniverse.getDataSource().loadPlotData(plotChunk.getWorldName(),plotChunk.getX(),plotChunk.getZ()) == null) { 110 | TownyUniverse.getDataSource().savePlotData(plotChunk); 111 | } 112 | } 113 | 114 | /** 115 | * Deletes a Plot Chunk snapshot from the datasource 116 | * 117 | * @param plotChunk 118 | */ 119 | public static void deletePlotChunkSnapshot(PlotBlockData plotChunk) { 120 | TownyUniverse.getDataSource().deletePlotData(plotChunk); 121 | } 122 | 123 | /** 124 | * Loads a Plot Chunk snapshot from the datasource 125 | * 126 | * @param townBlock 127 | */ 128 | public static PlotBlockData getPlotChunkSnapshot(TownBlock townBlock) { 129 | return TownyUniverse.getDataSource().loadPlotData(townBlock); 130 | } 131 | 132 | /** 133 | * Gets a Plot Chunk from the regeneration Hashtable 134 | * 135 | * @param townBlock 136 | */ 137 | public static PlotBlockData getPlotChunk(TownBlock townBlock) { 138 | if (PlotChunks.containsKey(getPlotKey(townBlock))) { 139 | return PlotChunks.get(getPlotKey(townBlock)); 140 | } 141 | return null; 142 | } 143 | 144 | private static String getPlotKey(PlotBlockData plotChunk) { 145 | return "[" + plotChunk.getWorldName() + "|" + plotChunk.getX() + "|" + plotChunk.getZ() + "]"; 146 | } 147 | 148 | public static String getPlotKey(TownBlock townBlock) { 149 | return "[" + townBlock.getWorld().getName() + "|" + townBlock.getX() + "|" + townBlock.getZ() + "]"; 150 | } 151 | 152 | /** 153 | * Restore the relevant chunk using the snapshot data. 154 | * 155 | * @param snapshot 156 | * @param resident 157 | */ 158 | public static void regenUndo (ChunkSnapshot snapshot, Resident resident) { 159 | 160 | byte data; 161 | int typeId; 162 | World world = Bukkit.getWorld(snapshot.getWorldName()); 163 | Chunk chunk = world.getChunkAt(MinecraftTools.calcChunk(snapshot.getX()), MinecraftTools.calcChunk(snapshot.getZ())); 164 | 165 | for (int x = 0 ; x < 16 ; x++) { 166 | for (int z = 0 ; z < 16 ; z++) { 167 | for (int y = 0 ; y < world.getMaxHeight() ; y++) { 168 | data = (byte) snapshot.getBlockData(x, y, z); 169 | typeId = snapshot.getBlockTypeId(x, y, z); 170 | chunk.getBlock(x, y, z).setTypeIdAndData(typeId, data, false); 171 | } 172 | } 173 | 174 | } 175 | 176 | TownyMessaging.sendMessage(Bukkit.getPlayerExact(resident.getName()), TownySettings.getLangString("msg_undo_complete")); 177 | 178 | } 179 | 180 | 181 | 182 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/townywar/listener/TownyWarCustomListener.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.townywar.listener; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.CustomEventListener; 8 | import org.bukkit.event.Event; 9 | 10 | import com.palmergames.bukkit.towny.NotRegisteredException; 11 | import com.palmergames.bukkit.towny.Towny; 12 | import com.palmergames.bukkit.towny.TownyException; 13 | import com.palmergames.bukkit.towny.TownyMessaging; 14 | import com.palmergames.bukkit.towny.TownySettings; 15 | import com.palmergames.bukkit.towny.command.TownCommand; 16 | import com.palmergames.bukkit.towny.object.Nation; 17 | import com.palmergames.bukkit.towny.object.Resident; 18 | import com.palmergames.bukkit.towny.object.Town; 19 | import com.palmergames.bukkit.towny.object.TownBlock; 20 | import com.palmergames.bukkit.towny.object.TownyUniverse; 21 | import com.palmergames.bukkit.towny.object.TownyWorld; 22 | import com.palmergames.bukkit.towny.object.WorldCoord; 23 | import com.palmergames.bukkit.towny.tasks.TownClaim; 24 | import com.palmergames.bukkit.townywar.CellUnderAttack; 25 | import com.palmergames.bukkit.townywar.TownyWar; 26 | import com.palmergames.bukkit.townywar.event.CellAttackCanceledEvent; 27 | import com.palmergames.bukkit.townywar.event.CellAttackEvent; 28 | import com.palmergames.bukkit.townywar.event.CellDefendedEvent; 29 | import com.palmergames.bukkit.townywar.event.CellWonEvent; 30 | 31 | public class TownyWarCustomListener extends CustomEventListener { 32 | private final Towny plugin; 33 | 34 | public TownyWarCustomListener(Towny instance) { 35 | plugin = instance; 36 | } 37 | 38 | @Override 39 | public void onCustomEvent(Event event) { 40 | if (event.getEventName().equals("CellAttack")) { 41 | CellAttackEvent cellAttackEvent = (CellAttackEvent)event; 42 | try { 43 | CellUnderAttack cell = cellAttackEvent.getData(); 44 | TownyWar.registerAttack(cell); 45 | } catch (Exception e) { 46 | cellAttackEvent.setCancelled(true); 47 | cellAttackEvent.setReason(e.getMessage()); 48 | } 49 | } else if (event.getEventName().equals("CellDefended")) { 50 | CellDefendedEvent cellDefendedEvent = (CellDefendedEvent)event; 51 | Player player = cellDefendedEvent.getPlayer(); 52 | CellUnderAttack cell = cellDefendedEvent.getCell().getAttackData(); 53 | 54 | TownyUniverse universe = plugin.getTownyUniverse(); 55 | try { 56 | TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName()); 57 | WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ()); 58 | universe.removeWarZone(worldCoord); 59 | 60 | plugin.updateCache(worldCoord); 61 | } catch (NotRegisteredException e) { 62 | e.printStackTrace(); 63 | } 64 | 65 | String playerName; 66 | if (player == null) { 67 | playerName = "Greater Forces"; 68 | } else { 69 | playerName = player.getName(); 70 | try { 71 | playerName = TownyUniverse.getDataSource().getResident(player.getName()).getFormattedName(); 72 | } catch (TownyException e) { 73 | } 74 | } 75 | 76 | plugin.getServer().broadcastMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_defended"), 77 | playerName, 78 | cell.getCellString())); 79 | } else if (event.getEventName().equals("CellWon")) { 80 | CellWonEvent cellWonEvent = (CellWonEvent)event; 81 | CellUnderAttack cell = cellWonEvent.getCellAttackData(); 82 | 83 | TownyUniverse universe = plugin.getTownyUniverse(); 84 | try { 85 | Resident resident = TownyUniverse.getDataSource().getResident(cell.getNameOfFlagOwner()); 86 | Town town = resident.getTown(); 87 | Nation nation = town.getNation(); 88 | 89 | TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName()); 90 | WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ()); 91 | universe.removeWarZone(worldCoord); 92 | 93 | TownBlock townBlock = worldCoord.getTownBlock(); 94 | TownyUniverse.getDataSource().removeTownBlock(townBlock); 95 | 96 | try { 97 | List selection = new ArrayList(); 98 | selection.add(worldCoord); 99 | TownCommand.checkIfSelectionIsValid(town, selection, false, 0, false); 100 | new TownClaim(plugin, null, town, selection, true, false).start(); 101 | 102 | //TownCommand.townClaim(town, worldCoord); 103 | //TownyUniverse.getDataSource().saveTown(town); 104 | //TownyUniverse.getDataSource().saveWorld(world); 105 | 106 | //TODO 107 | //PlotCommand.plotClaim(resident, worldCoord); 108 | //TownyUniverse.getDataSource().saveResident(resident); 109 | //TownyUniverse.getDataSource().saveWorld(world); 110 | } catch (TownyException te) { 111 | // Couldn't claim it. 112 | } 113 | 114 | plugin.updateCache(worldCoord); 115 | 116 | TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_won"), 117 | resident.getFormattedName(), 118 | (nation.hasTag() ? nation.getTag() : nation.getFormattedName()), 119 | cell.getCellString())); 120 | } catch (NotRegisteredException e) { 121 | e.printStackTrace(); 122 | } 123 | } else if (event.getEventName().equals("CellAttackCanceled")) { 124 | System.out.println("CellAttackCanceled"); 125 | CellAttackCanceledEvent cancelCellAttackerEvent = (CellAttackCanceledEvent)event; 126 | CellUnderAttack cell = cancelCellAttackerEvent.getCell(); 127 | 128 | TownyUniverse universe = plugin.getTownyUniverse(); 129 | try { 130 | TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName()); 131 | WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ()); 132 | universe.removeWarZone(worldCoord); 133 | plugin.updateCache(worldCoord); 134 | } catch (NotRegisteredException e) { 135 | e.printStackTrace(); 136 | } 137 | System.out.println(cell.getCellString()); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/ProtectionRegenTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import org.bukkit.Material; 4 | import org.bukkit.block.Block; 5 | import org.bukkit.block.BlockFace; 6 | import org.bukkit.block.BlockState; 7 | import org.bukkit.block.Sign; 8 | import org.bukkit.material.Attachable; 9 | import org.bukkit.material.Door; 10 | import org.bukkit.material.PistonExtensionMaterial; 11 | 12 | import com.palmergames.bukkit.towny.object.BlockLocation; 13 | import com.palmergames.bukkit.towny.object.NeedsPlaceholder; 14 | import com.palmergames.bukkit.towny.object.TownyUniverse; 15 | 16 | public class ProtectionRegenTask extends TownyTimerTask { 17 | 18 | private BlockState state; 19 | private BlockState altState; 20 | private BlockLocation blockLocation; 21 | private int TaskId; 22 | 23 | private static final Material placeholder = Material.DIRT; 24 | 25 | public ProtectionRegenTask(TownyUniverse universe, Block block, boolean update) { 26 | super(universe); 27 | this.state = block.getState(); 28 | this.altState = null; 29 | this.setBlockLocation(new BlockLocation(block.getLocation())); 30 | 31 | if (update) 32 | if(state.getData() instanceof Door) { 33 | Door door = (Door)state.getData(); 34 | Block topHalf; 35 | Block bottomHalf; 36 | if(door.isTopHalf()) { 37 | topHalf = block; 38 | bottomHalf = block.getRelative(BlockFace.DOWN); 39 | } else { 40 | bottomHalf = block; 41 | topHalf = block.getRelative(BlockFace.UP); 42 | } 43 | bottomHalf.setTypeId(0); 44 | topHalf.setTypeId(0); 45 | } else if(state.getData() instanceof PistonExtensionMaterial) { 46 | PistonExtensionMaterial extension = (PistonExtensionMaterial)state.getData(); 47 | Block piston = block.getRelative(extension.getAttachedFace()); 48 | if(piston.getTypeId() != 0) { 49 | this.altState = piston.getState(); 50 | piston.setTypeId(0, false); 51 | } 52 | block.setTypeId(0, false); 53 | } else { 54 | block.setTypeId(0, false); 55 | } 56 | } 57 | 58 | @Override 59 | public void run() { 60 | replaceProtections(); 61 | universe.removeProtectionRegenTask(this); 62 | } 63 | 64 | public void replaceProtections() { 65 | Block block = state.getBlock(); 66 | if(state.getData() instanceof Door) { 67 | Door door = (Door)state.getData(); 68 | Block topHalf; 69 | Block bottomHalf; 70 | if(door.isTopHalf()) { 71 | topHalf = block; 72 | bottomHalf = block.getRelative(BlockFace.DOWN); 73 | } else { 74 | bottomHalf = block; 75 | topHalf = block.getRelative(BlockFace.UP); 76 | } 77 | door.setTopHalf(true); 78 | topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false); 79 | door.setTopHalf(false); 80 | bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false); 81 | } else if(state instanceof Sign) { 82 | block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false); 83 | Sign sign = (Sign)block.getState(); 84 | int i = 0; 85 | for(String line : ((Sign)state).getLines()) 86 | sign.setLine(i++, line); 87 | } else if(state.getData() instanceof PistonExtensionMaterial) { 88 | PistonExtensionMaterial extension = (PistonExtensionMaterial)state.getData(); 89 | Block piston = block.getRelative(extension.getAttachedFace()); 90 | block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false); 91 | if(altState != null) { 92 | piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false); 93 | } 94 | } else if(state.getData() instanceof Attachable) { 95 | Block attachedBlock = block.getRelative(((Attachable)state.getData()).getAttachedFace()); 96 | if(attachedBlock.getTypeId() == 0) { 97 | attachedBlock.setTypeId(placeholder.getId(), false); 98 | universe.addPlaceholder(attachedBlock); 99 | } 100 | block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false); 101 | } else { 102 | if(NeedsPlaceholder.contains(state.getType())) { 103 | Block blockBelow = block.getRelative(BlockFace.DOWN); 104 | if(blockBelow.getTypeId() == 0) { 105 | if(state.getType().equals(Material.CROPS)) { 106 | blockBelow.setTypeId(Material.SOIL.getId(), true); 107 | } else { 108 | blockBelow.setTypeId(placeholder.getId(), true); 109 | } 110 | universe.addPlaceholder(blockBelow); 111 | } 112 | } 113 | block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType())); 114 | } 115 | universe.removePlaceholder(block); 116 | } 117 | 118 | /** 119 | * @return the blockLocation 120 | */ 121 | public BlockLocation getBlockLocation() { 122 | return blockLocation; 123 | } 124 | 125 | /** 126 | * @param blockLocation the blockLocation to set 127 | */ 128 | private void setBlockLocation(BlockLocation blockLocation) { 129 | this.blockLocation = blockLocation; 130 | } 131 | 132 | public BlockState getState() { 133 | return state; 134 | } 135 | 136 | /** 137 | * @return the taskId 138 | */ 139 | public int getTaskId() { 140 | return TaskId; 141 | } 142 | 143 | /** 144 | * @param taskId the taskId to set 145 | */ 146 | public void setTaskId(int taskId) { 147 | TaskId = taskId; 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/TownyPermissionSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | import org.anjocaido.groupmanager.GroupManager; 4 | import org.bukkit.entity.Player; 5 | import ru.tehkode.permissions.bukkit.PermissionsEx; 6 | 7 | import com.palmergames.bukkit.towny.Towny; 8 | import com.palmergames.bukkit.towny.TownySettings; 9 | import com.palmergames.bukkit.towny.object.Resident; 10 | import com.palmergames.bukkit.towny.object.TownyPermission; 11 | import com.palmergames.bukkit.towny.object.TownyWorld; 12 | 13 | 14 | /** 15 | * @author ElgarL 16 | * 17 | * Manager for Permission provider plugins 18 | * 19 | */ 20 | public abstract class TownyPermissionSource { 21 | protected TownySettings settings; 22 | protected Towny plugin; 23 | 24 | protected GroupManager groupManager = null; 25 | //protected de.bananaco.permissions.Permissions bPermissions = null; 26 | protected com.nijikokun.bukkit.Permissions.Permissions permissions = null; 27 | protected PermissionsEx pex = null; 28 | 29 | 30 | abstract public String getPrefixSuffix(Resident resident, String node); 31 | abstract public int getGroupPermissionIntNode(String playerName, String node); 32 | abstract public boolean hasPermission(Player player, String node); 33 | abstract public String getPlayerGroup(Player player); 34 | abstract public String getPlayerPermissionStringNode(String playerName, String node); 35 | 36 | public boolean hasWildOverride(TownyWorld world, Player player, int blockId, TownyPermission.ActionType action) { 37 | 38 | boolean bpermissions; 39 | 40 | //check for permissions 41 | if (bpermissions = plugin.isPermissions()) 42 | if ((hasPermission(player, PermissionNodes.TOWNY_WILD_ALL.getNode(action.toString().toLowerCase()))) 43 | || (hasPermission(player, PermissionNodes.TOWNY_WILD_BLOCK_ALL.getNode(blockId + "." + action.toString().toLowerCase())))) 44 | return true; 45 | 46 | // Allow ops all access when no permissions 47 | if ((!bpermissions) && (isTownyAdmin(player))) 48 | return true; 49 | 50 | // No perms so check world settings. 51 | switch (action) { 52 | 53 | case BUILD: 54 | return world.getUnclaimedZoneBuild() 55 | || (bpermissions && hasPermission(player, PermissionNodes.TOWNY_WILD_BLOCK_BUILD.getNode())) 56 | || (!bpermissions && world.isUnclaimedZoneIgnoreId(blockId)); 57 | case DESTROY: 58 | return world.getUnclaimedZoneDestroy() 59 | || (bpermissions && hasPermission(player, PermissionNodes.TOWNY_WILD_BLOCK_DESTROY.getNode())) 60 | || (!bpermissions && world.isUnclaimedZoneIgnoreId(blockId)); 61 | case SWITCH: 62 | return world.getUnclaimedZoneSwitch() 63 | || (bpermissions && hasPermission(player, PermissionNodes.TOWNY_WILD_BLOCK_SWITCH.getNode())) 64 | || (!bpermissions && world.isUnclaimedZoneIgnoreId(blockId)); 65 | case ITEM_USE: 66 | return world.getUnclaimedZoneItemUse() 67 | || (bpermissions && hasPermission(player, PermissionNodes.TOWNY_WILD_BLOCK_ITEM_USE.getNode())) 68 | || (!bpermissions && world.isUnclaimedZoneIgnoreId(blockId)); 69 | default: 70 | return false; 71 | } 72 | } 73 | 74 | public boolean hasOwnTownOverride(Player player, int blockId, TownyPermission.ActionType action) { 75 | 76 | boolean bpermissions; 77 | 78 | //check for permissions 79 | if (bpermissions = plugin.isPermissions()) 80 | if ((hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL.getNode(action.toString().toLowerCase()))) 81 | || (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK.getNode(blockId + "." + action.toString().toLowerCase()))) 82 | || (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_OWNTOWN_BLOCK.getNode(blockId + "." + action.toString().toLowerCase())))) 83 | return true; 84 | 85 | // Allow ops all access when no permissions 86 | if ((!bpermissions) && (isTownyAdmin(player))) 87 | return true; 88 | 89 | // No perms so check global settings. 90 | switch (action) { 91 | 92 | case BUILD: 93 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_BUILD.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_OWNTOWN_BLOCK_BUILD.getNode()))); 94 | case DESTROY: 95 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_DESTROY.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_OWNTOWN_BLOCK_DESTROY.getNode()))); 96 | case SWITCH: 97 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_SWITCH.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_OWNTOWN_BLOCK_SWITCH.getNode()))); 98 | case ITEM_USE: 99 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ITEM_USE.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_OWNTOWN_BLOCK_ITEM_USE.getNode()))); 100 | default: 101 | return false; 102 | } 103 | } 104 | 105 | public boolean hasAllTownOverride(Player player, int blockId, TownyPermission.ActionType action) { 106 | 107 | boolean bpermissions; 108 | 109 | //check for permissions 110 | if (bpermissions = plugin.isPermissions()) 111 | if ((hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL.getNode(action.toString().toLowerCase()))) 112 | || (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK.getNode(blockId + "." + action.toString().toLowerCase())))) 113 | return true; 114 | 115 | // Allow ops all access when no permissions 116 | if ((!bpermissions) && (isTownyAdmin(player))) 117 | return true; 118 | 119 | // No perms so check global settings. 120 | switch (action) { 121 | 122 | case BUILD: 123 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_BUILD.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK_BUILD.getNode()))); 124 | case DESTROY: 125 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_DESTROY.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK_DESTROY.getNode()))); 126 | case SWITCH: 127 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_SWITCH.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK_SWITCH.getNode()))); 128 | case ITEM_USE: 129 | return (bpermissions && (hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ITEM_USE.getNode()) || hasPermission(player, PermissionNodes.TOWNY_CLAIMED_ALL_BLOCK_ITEM_USE.getNode()))); 130 | default: 131 | return false; 132 | } 133 | } 134 | 135 | public boolean isTownyAdmin(Player player) { 136 | if (player.isOp()) 137 | return true; 138 | return hasPermission(player, PermissionNodes.TOWNY_ADMIN.getNode()); 139 | } 140 | 141 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/Resident.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.bukkit.ChunkSnapshot; 8 | 9 | import com.palmergames.bukkit.towny.*; 10 | 11 | public class Resident extends TownBlockOwner { 12 | private List friends = new ArrayList(); 13 | private List regenUndo = new ArrayList(); 14 | private Town town; 15 | private long lastOnline, registered; 16 | private boolean isNPC = false; 17 | private String title, surname; 18 | private long teleportRequestTime; 19 | private Town teleportDestination; 20 | private double teleportCost; 21 | private String chatFormattedName; 22 | 23 | public Resident(String name) { 24 | setChatFormattedName(name); 25 | setName(name); 26 | setTitle(""); 27 | setSurname(""); 28 | permissions.loadDefault(this); 29 | teleportRequestTime = -1; 30 | teleportCost = 0.0; 31 | } 32 | 33 | public void setLastOnline(long lastOnline) { 34 | this.lastOnline = lastOnline; 35 | } 36 | 37 | public long getLastOnline() { 38 | return lastOnline; 39 | } 40 | 41 | public void setNPC(boolean isNPC) { 42 | this.isNPC = isNPC; 43 | } 44 | 45 | public boolean isNPC() { 46 | return isNPC; 47 | } 48 | 49 | public void setTitle(String title) { 50 | if (title.matches(" ")) 51 | title = ""; 52 | this.title = title; 53 | setChangedName(true); 54 | } 55 | 56 | public String getTitle() { 57 | return title; 58 | } 59 | 60 | public boolean hasTitle() { 61 | return !title.isEmpty(); 62 | } 63 | 64 | public void setSurname(String surname) { 65 | if (surname.matches(" ")) 66 | surname = ""; 67 | this.surname = surname; 68 | setChangedName(true); 69 | } 70 | 71 | public String getSurname() { 72 | return surname; 73 | } 74 | 75 | public boolean hasSurname() { 76 | return !surname.isEmpty(); 77 | } 78 | 79 | public boolean isKing() { 80 | try { 81 | return getTown().getNation().isKing(this); 82 | } catch (TownyException e) { 83 | return false; 84 | } 85 | } 86 | 87 | public boolean isMayor() { 88 | return hasTown() ? town.isMayor(this) : false; 89 | } 90 | 91 | public boolean hasTown() { 92 | return !(town == null); 93 | } 94 | 95 | public boolean hasNation() { 96 | return hasTown() ? town.hasNation() : false; 97 | } 98 | 99 | public Town getTown() throws NotRegisteredException { 100 | if (hasTown()) 101 | return town; 102 | else 103 | throw new NotRegisteredException( 104 | "Resident doesn't belong to any town"); 105 | } 106 | 107 | public void setTown(Town town) throws AlreadyRegisteredException { 108 | if (town == null) { 109 | this.town = null; 110 | setTitle(""); 111 | setSurname(""); 112 | return; 113 | } 114 | if (this.town == town) 115 | return; 116 | if (hasTown()) 117 | throw new AlreadyRegisteredException(); 118 | this.town = town; 119 | setTitle(""); 120 | setSurname(""); 121 | } 122 | 123 | public void setFriends(List newFriends) { 124 | friends = newFriends; 125 | } 126 | 127 | public List getFriends() { 128 | return friends; 129 | } 130 | 131 | public boolean removeFriend(Resident resident) throws NotRegisteredException { 132 | if (hasFriend(resident)) 133 | return friends.remove(resident); 134 | else 135 | throw new NotRegisteredException(); 136 | } 137 | 138 | public boolean hasFriend(Resident resident) { 139 | return friends.contains(resident); 140 | } 141 | 142 | public void addFriend(Resident resident) throws AlreadyRegisteredException { 143 | if (hasFriend(resident)) 144 | throw new AlreadyRegisteredException(); 145 | else 146 | friends.add(resident); 147 | } 148 | 149 | public void removeAllFriends() { 150 | for (Resident resident : new ArrayList(friends)) 151 | try { 152 | removeFriend(resident); 153 | } catch (NotRegisteredException e) { 154 | } 155 | } 156 | 157 | public void clear() throws EmptyTownException { 158 | removeAllFriends(); 159 | //setLastOnline(0); 160 | 161 | if (hasTown()) 162 | try { 163 | town.removeResident(this); 164 | setTitle(""); 165 | setSurname(""); 166 | } catch (NotRegisteredException e) { 167 | } 168 | } 169 | 170 | public void setRegistered(long registered) { 171 | this.registered = registered; 172 | } 173 | 174 | public long getRegistered() { 175 | return registered; 176 | } 177 | 178 | @Override 179 | public List getTreeString(int depth) { 180 | List out = new ArrayList(); 181 | out.add(getTreeDepth(depth) + "Resident ("+getName()+")"); 182 | out.add(getTreeDepth(depth+1) + "Registered: " + getRegistered()); 183 | out.add(getTreeDepth(depth+1) + "Last Online: " + getLastOnline()); 184 | if (getFriends().size() > 0) 185 | out.add(getTreeDepth(depth+1) + "Friends (" + getFriends().size() + "): " + Arrays.toString(getFriends().toArray(new Resident[0]))); 186 | return out; 187 | } 188 | 189 | public void clearTeleportRequest() { 190 | teleportRequestTime = -1; 191 | } 192 | 193 | public void setTeleportRequestTime() { 194 | teleportRequestTime = System.currentTimeMillis(); 195 | } 196 | 197 | public long getTeleportRequestTime() { 198 | return teleportRequestTime; 199 | } 200 | 201 | public void setTeleportDestination(Town town) { 202 | teleportDestination = town; 203 | } 204 | 205 | public Town getTeleportDestination() { 206 | return teleportDestination; 207 | } 208 | 209 | public boolean hasRequestedTeleport() { 210 | return teleportRequestTime != -1; 211 | } 212 | 213 | public void setTeleportCost(double cost) { 214 | teleportCost = cost; 215 | } 216 | public double getTeleportCost() { 217 | return teleportCost; 218 | } 219 | 220 | /** 221 | * @return the chatFormattedName 222 | */ 223 | public String getChatFormattedName() { 224 | return chatFormattedName; 225 | } 226 | 227 | /** 228 | * @param chatFormattedName the chatFormattedName to set 229 | */ 230 | public void setChatFormattedName(String chatFormattedName) { 231 | this.chatFormattedName = chatFormattedName; 232 | setChangedName(false); 233 | } 234 | 235 | /** 236 | * Push a snapshot to the Undo queue 237 | * 238 | * @param snapshot 239 | */ 240 | public void addUndo(ChunkSnapshot snapshot) { 241 | if (regenUndo.size() == 5) 242 | regenUndo.remove(0); 243 | regenUndo.add(snapshot); 244 | } 245 | 246 | public void regenUndo () { 247 | if (regenUndo.size() > 0) { 248 | ChunkSnapshot snapshot = regenUndo.get(regenUndo.size()-1); 249 | regenUndo.remove(snapshot); 250 | 251 | TownyRegenAPI.regenUndo(snapshot, this); 252 | 253 | } 254 | } 255 | 256 | } 257 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/MobRemovalTimerTask.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Server; 7 | import org.bukkit.World; 8 | import org.bukkit.entity.LivingEntity; 9 | 10 | import com.palmergames.bukkit.towny.NotRegisteredException; 11 | import com.palmergames.bukkit.towny.TownyException; 12 | import com.palmergames.bukkit.towny.TownyMessaging; 13 | import com.palmergames.bukkit.towny.TownySettings; 14 | import com.palmergames.bukkit.towny.object.Coord; 15 | import com.palmergames.bukkit.towny.object.TownBlock; 16 | import com.palmergames.bukkit.towny.object.TownyUniverse; 17 | import com.palmergames.bukkit.towny.object.TownyWorld; 18 | import com.palmergames.util.JavaUtil; 19 | 20 | 21 | public class MobRemovalTimerTask extends TownyTimerTask { 22 | private Server server; 23 | @SuppressWarnings("rawtypes") 24 | public static List worldMobsToRemove = new ArrayList(); 25 | @SuppressWarnings("rawtypes") 26 | public static List townMobsToRemove = new ArrayList(); 27 | 28 | @SuppressWarnings("rawtypes") 29 | public MobRemovalTimerTask(TownyUniverse universe, Server server) { 30 | super(universe); 31 | this.server = server; 32 | 33 | worldMobsToRemove.clear(); 34 | for (String mob : TownySettings.getWorldMobRemovalEntities()) 35 | if (!mob.equals("")) 36 | try { 37 | Class c = Class.forName("org.bukkit.entity."+mob); 38 | if (JavaUtil.isSubInterface(LivingEntity.class, c)) 39 | worldMobsToRemove.add(c); 40 | else 41 | throw new Exception(); 42 | } catch (ClassNotFoundException e) { 43 | TownyMessaging.sendErrorMsg("WorldMob: " + mob + " is not an acceptable class."); 44 | } catch (Exception e) { 45 | TownyMessaging.sendErrorMsg("WorldMob: " + mob + " is not an acceptable living entity."); 46 | } 47 | 48 | townMobsToRemove.clear(); 49 | for (String mob : TownySettings.getTownMobRemovalEntities()) 50 | if (!mob.equals("")) 51 | try { 52 | Class c = Class.forName("org.bukkit.entity."+mob); 53 | if (JavaUtil.isSubInterface(LivingEntity.class, c)) 54 | townMobsToRemove.add(c); 55 | else 56 | throw new Exception(); 57 | } catch (ClassNotFoundException e) { 58 | TownyMessaging.sendErrorMsg("TownMob: " + mob + " is not an acceptable class."); 59 | } catch (Exception e) { 60 | TownyMessaging.sendErrorMsg("TownMob: " + mob + " is not an acceptable living entity."); 61 | } 62 | } 63 | 64 | 65 | @SuppressWarnings("rawtypes") 66 | public static boolean isRemovingWorldEntity(LivingEntity livingEntity) { 67 | for (Class c : worldMobsToRemove) 68 | if (c.isInstance(livingEntity)) 69 | return true; 70 | else if (c.getName().contains(livingEntity.toString())) 71 | System.out.print(livingEntity.toString()); 72 | return false; 73 | } 74 | 75 | @SuppressWarnings("rawtypes") 76 | public static boolean isRemovingTownEntity(LivingEntity livingEntity) { 77 | for (Class c : townMobsToRemove) 78 | if (c.isInstance(livingEntity)) 79 | return true; 80 | else if (c.getName().contains(livingEntity.toString())) 81 | System.out.print(livingEntity.toString()); 82 | return false; 83 | } 84 | 85 | 86 | @Override 87 | public void run() { 88 | //int numRemoved = 0; 89 | //int livingEntities = 0; 90 | 91 | /* OLD METHOD 92 | for (World world : server.getWorlds()) { 93 | List worldLivingEntities = new ArrayList(world.getLivingEntities()); 94 | livingEntities += worldLivingEntities.size(); 95 | for (LivingEntity livingEntity : worldLivingEntities) 96 | if (isRemovingEntity(livingEntity)) { 97 | Location loc = livingEntity.getLocation(); 98 | Coord coord = Coord.parseCoord(loc); 99 | try { 100 | TownyWorld townyWorld = universe.getWorld(world.getName()); 101 | TownBlock townBlock = townyWorld.getTownBlock(coord); 102 | if (!townBlock.getTown().hasMobs()) { 103 | //universe.getPlugin().sendDebugMsg("MobRemoval Removed: " + livingEntity.toString()); 104 | livingEntity.teleportTo(new Location(world, loc.getX(), -50, loc.getZ())); 105 | numRemoved++; 106 | } 107 | } catch (TownyException x) { 108 | } 109 | } 110 | //universe.getPlugin().sendDebugMsg(world.getName() + ": " + StringMgmt.join(worldLivingEntities)); 111 | } 112 | //universe.getPlugin().sendDebugMsg("MobRemoval (Removed: "+numRemoved+") (Total Living: "+livingEntities+")"); 113 | */ 114 | 115 | //System.out.println("[Towny] MobRemovalTimerTask - run()"); 116 | 117 | //boolean isRemovingWorldMobs = TownySettings.isRemovingWorldMobs(); 118 | //boolean isRemovingTownMobs = TownySettings.isRemovingTownMobs(); 119 | 120 | // Build a list of mobs to be removed 121 | //if (isRemovingTownMobs || isRemovingWorldMobs) 122 | for (World world : server.getWorlds()) { 123 | List livingEntitiesToRemove = new ArrayList(); 124 | 125 | for (LivingEntity livingEntity : world.getLivingEntities()) { 126 | Coord coord = Coord.parseCoord(livingEntity.getLocation()); 127 | TownyWorld townyWorld = null; 128 | try { 129 | townyWorld = TownyUniverse.getDataSource().getWorld(world.getName()); 130 | } catch (NotRegisteredException e) { 131 | // TODO Auto-generated catch block 132 | e.printStackTrace(); 133 | } 134 | try { 135 | TownBlock townBlock = townyWorld.getTownBlock(coord); 136 | if ((!townBlock.getTown().hasMobs() && !townBlock.getPermissions().mobs && isRemovingTownEntity(livingEntity))) { 137 | //System.out.println("[Towny] Town MobRemovalTimerTask - added: " + livingEntity.toString()); 138 | livingEntitiesToRemove.add(livingEntity); 139 | } 140 | 141 | } catch (TownyException x) { 142 | // it will fall through here if the mob has no townblock. 143 | if ((!townyWorld.hasWorldMobs() && isRemovingWorldEntity(livingEntity))) { 144 | //System.out.println("[Towny] World MobRemovalTimerTask - added: " + livingEntity.toString()); 145 | livingEntitiesToRemove.add(livingEntity); 146 | } 147 | } 148 | } 149 | 150 | 151 | for (LivingEntity livingEntity : livingEntitiesToRemove) { 152 | TownyMessaging.sendDebugMsg("MobRemoval Removed: " + livingEntity.toString()); 153 | //livingEntity.teleportTo(new Location(world, livingEntity.getLocation().getX(), -50, livingEntity.getLocation().getZ())); 154 | livingEntity.remove(); 155 | //numRemoved++; 156 | } 157 | 158 | //universe.getPlugin().sendDebugMsg(world.getName() + ": " + StringMgmt.join(worldLivingEntities)); 159 | 160 | } 161 | 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/GroupManagerSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | import org.anjocaido.groupmanager.GroupManager; 4 | import org.anjocaido.groupmanager.data.Group; 5 | import org.anjocaido.groupmanager.events.GMGroupEvent; 6 | import org.anjocaido.groupmanager.events.GMSystemEvent; 7 | import org.anjocaido.groupmanager.events.GMUserEvent; 8 | import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler; 9 | import org.bukkit.entity.Player; 10 | import org.bukkit.event.CustomEventListener; 11 | import org.bukkit.event.Event; 12 | import org.bukkit.event.Event.Priority; 13 | import org.bukkit.plugin.Plugin; 14 | 15 | import com.palmergames.bukkit.towny.NotRegisteredException; 16 | import com.palmergames.bukkit.towny.Towny; 17 | import com.palmergames.bukkit.towny.TownySettings; 18 | import com.palmergames.bukkit.towny.object.Resident; 19 | import com.palmergames.bukkit.towny.object.TownyUniverse; 20 | 21 | /** 22 | * @author ElgarL 23 | * 24 | */ 25 | public class GroupManagerSource extends TownyPermissionSource { 26 | 27 | public GroupManagerSource(Towny towny, Plugin test) { 28 | this.groupManager = (GroupManager) test; 29 | this.plugin = towny; 30 | 31 | plugin.getServer().getPluginManager().registerEvent(Event.Type.CUSTOM_EVENT, new GMCustomEventListener(), Priority.High, plugin); 32 | } 33 | 34 | /** 35 | * getPermissionNode 36 | * 37 | * returns the specified prefix/suffix nodes from GroupManager 38 | * 39 | * @param resident 40 | * @param node 41 | * @return String of the Prefix or Suffix. 42 | */ 43 | @Override 44 | public String getPrefixSuffix(Resident resident, String node) { 45 | 46 | String group = "", user = ""; 47 | Player player = this.plugin.getServer().getPlayer(resident.getName()); 48 | 49 | //sendDebugMsg(" GroupManager installed."); 50 | AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldData(player).getPermissionsHandler(); 51 | 52 | if (node == "prefix") { 53 | group = handler.getGroupPrefix(handler.getPrimaryGroup(player.getName())); 54 | user = handler.getUserPrefix(player.getName()); 55 | } else if (node == "suffix") { 56 | group = handler.getGroupSuffix(handler.getPrimaryGroup(player.getName())); 57 | user = handler.getUserSuffix(player.getName()); 58 | } 59 | 60 | if (!group.equals(user)) 61 | user = group + user; 62 | user = TownySettings.parseSingleLineString(user); 63 | 64 | return user; 65 | 66 | } 67 | 68 | /** 69 | * 70 | * @param playerName 71 | * @param node 72 | * @return -1 = can't find 73 | */ 74 | @Override 75 | public int getGroupPermissionIntNode(String playerName, String node) { 76 | Player player = plugin.getServer().getPlayer(playerName); 77 | 78 | AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldData(player).getPermissionsHandler(); 79 | return handler.getPermissionInteger(playerName, node); 80 | 81 | } 82 | 83 | /** 84 | * 85 | * @param playerName 86 | * @param node 87 | * @return empty = can't find 88 | */ 89 | @Override 90 | public String getPlayerPermissionStringNode(String playerName, String node) { 91 | Player player = plugin.getServer().getPlayer(playerName); 92 | 93 | AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldData(player).getPermissionsHandler(); 94 | 95 | return handler.getPermissionString(playerName, node); 96 | 97 | } 98 | 99 | /** 100 | * hasPermission 101 | * 102 | * returns if a player has a certain permission node. 103 | * 104 | * @param player 105 | * @param node 106 | * @return true is Op or has the permission node. 107 | */ 108 | @Override 109 | public boolean hasPermission(Player player, String node) { 110 | 111 | if (player.isOp()) 112 | return true; 113 | 114 | AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldData(player).getPermissionsHandler(); 115 | return handler.has(player, node); 116 | } 117 | 118 | /** 119 | * Returns the players Group name. 120 | * 121 | * @param player 122 | * @return name of players group 123 | */ 124 | @Override 125 | public String getPlayerGroup(Player player) { 126 | AnjoPermissionsHandler handler = groupManager.getWorldsHolder().getWorldData(player).getPermissionsHandler(); 127 | return handler.getGroup(player.getName()); 128 | } 129 | 130 | protected class GMCustomEventListener extends CustomEventListener { 131 | 132 | public GMCustomEventListener() { 133 | } 134 | 135 | @Override 136 | public void onCustomEvent(Event event) { 137 | 138 | Resident resident = null; 139 | Player player = null; 140 | 141 | try { 142 | if (event instanceof GMUserEvent) { 143 | 144 | if (PermissionEventEnums.GMUser_Action.valueOf(event.getEventName()) != null) { 145 | GMUserEvent UserEvent = (GMUserEvent) event; 146 | try { 147 | resident = TownyUniverse.getDataSource().getResident(UserEvent.getUserName()); 148 | player = plugin.getServer().getPlayerExact(resident.getName()); 149 | if (player != null) { 150 | //setup default modes for this player. 151 | String[] modes = getPlayerPermissionStringNode(player.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 152 | plugin.setPlayerMode(player, modes, false); 153 | } 154 | } catch (NotRegisteredException x) { 155 | } 156 | 157 | } 158 | } else if (event instanceof GMGroupEvent) { 159 | if (PermissionEventEnums.GMGroup_Action.valueOf(event.getEventName()) != null) { 160 | GMGroupEvent GroupEvent = (GMGroupEvent) event; 161 | Group group = GroupEvent.getGroup(); 162 | // Update all players who are in this group. 163 | for (Player toUpdate : TownyUniverse.getOnlinePlayers()) { 164 | if (group.equals(getPlayerGroup(toUpdate))) { 165 | //setup default modes 166 | String[] modes = getPlayerPermissionStringNode(toUpdate.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 167 | plugin.setPlayerMode(player, modes, false); 168 | } 169 | } 170 | 171 | } 172 | 173 | } else if (event instanceof GMSystemEvent) { 174 | if (PermissionEventEnums.GMGroup_Action.valueOf(event.getEventName()) != null) { 175 | // Update all players. 176 | for (Player toUpdate : TownyUniverse.getOnlinePlayers()) { 177 | //setup default modes 178 | String[] modes = getPlayerPermissionStringNode(toUpdate.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 179 | plugin.setPlayerMode(player, modes, false); 180 | } 181 | 182 | } 183 | 184 | } 185 | } catch (IllegalArgumentException ex) { 186 | // We are not looking for this event type. 187 | } 188 | 189 | } 190 | } 191 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/TownBlock.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 4 | import com.palmergames.bukkit.towny.NotRegisteredException; 5 | import com.palmergames.bukkit.towny.TownyException; 6 | import com.palmergames.bukkit.towny.TownySettings; 7 | 8 | public class TownBlock { 9 | // TODO: Admin only or possibly a group check 10 | // private List groups; 11 | private TownyWorld world; 12 | private Town town; 13 | private Resident resident; 14 | private TownBlockType type; 15 | private int x, z; 16 | private double plotPrice = -1; 17 | private boolean locked = false; 18 | 19 | //Plot level permissions 20 | protected TownyPermission permissions = new TownyPermission(); 21 | protected boolean isChanged; 22 | 23 | public TownBlock(int x, int z, TownyWorld world) { 24 | this.x = x; 25 | this.z = z; 26 | this.setWorld(world); 27 | this.type = TownBlockType.RESIDENTIAL; 28 | isChanged = false; 29 | } 30 | 31 | public void setTown(Town town) { 32 | try { 33 | if (hasTown()) 34 | this.town.removeTownBlock(this); 35 | } catch (NotRegisteredException e) { 36 | } 37 | this.town = town; 38 | try { 39 | town.addTownBlock(this); 40 | } catch (AlreadyRegisteredException e) { 41 | } catch (NullPointerException e) { 42 | } 43 | } 44 | 45 | public Town getTown() throws NotRegisteredException { 46 | if (!hasTown()) 47 | throw new NotRegisteredException(); 48 | return town; 49 | } 50 | 51 | public boolean hasTown() { 52 | return town != null; 53 | } 54 | 55 | public void setResident(Resident resident) { 56 | try { 57 | if (hasResident()) 58 | this.resident.removeTownBlock(this); 59 | } catch (NotRegisteredException e) { 60 | } 61 | this.resident = resident; 62 | try { 63 | resident.addTownBlock(this); 64 | } catch (AlreadyRegisteredException e) { 65 | } catch (NullPointerException e) { 66 | } 67 | } 68 | 69 | public Resident getResident() throws NotRegisteredException { 70 | if (!hasResident()) 71 | throw new NotRegisteredException(); 72 | return resident; 73 | } 74 | 75 | public boolean hasResident() { 76 | return resident != null; 77 | } 78 | 79 | public boolean isOwner(TownBlockOwner owner) { 80 | try { 81 | if (owner == getTown()) 82 | return true; 83 | } catch (NotRegisteredException e) { 84 | } 85 | 86 | try { 87 | if (owner == getResident()) 88 | return true; 89 | } catch (NotRegisteredException e) { 90 | } 91 | 92 | return false; 93 | } 94 | 95 | public void setPlotPrice(double ForSale) { 96 | this.plotPrice = ForSale; 97 | 98 | } 99 | 100 | public double getPlotPrice() { 101 | return plotPrice; 102 | } 103 | 104 | public boolean isForSale() { 105 | return getPlotPrice() != -1.0; 106 | } 107 | 108 | public void setPermissions(String line) { 109 | //permissions.reset(); not needed, already done in permissions.load() 110 | permissions.load(line); 111 | } 112 | 113 | public TownyPermission getPermissions() { 114 | return permissions; 115 | } 116 | 117 | /** 118 | * Have the permissions been manually changed. 119 | * 120 | * @return the isChanged 121 | */ 122 | public boolean isChanged() { 123 | return isChanged; 124 | } 125 | 126 | /** 127 | * Flag the permissions as changed. 128 | * 129 | * @param isChanged the isChanged to set 130 | */ 131 | public void setChanged(boolean isChanged) { 132 | this.isChanged = isChanged; 133 | } 134 | 135 | public TownBlockType getType() { 136 | return type; 137 | } 138 | 139 | public void setType(TownBlockType type) { 140 | if (type != this.type) 141 | this.permissions.reset(); 142 | this.type = type; 143 | 144 | // Custom plot settings here 145 | switch(type) { 146 | case RESIDENTIAL: 147 | if (this.hasResident()) { 148 | setPermissions(this.resident.permissions.toString()); 149 | } else { 150 | setPermissions(this.town.permissions.toString()); 151 | } 152 | break; 153 | case COMMERCIAL: 154 | setPermissions("residentSwitch,allySwitch,outsiderSwitch"); 155 | break; 156 | case ARENA: 157 | setPermissions("pvp"); 158 | break; 159 | case EMBASSY: 160 | if (this.hasResident()) 161 | setPermissions(this.resident.permissions.toString()); 162 | else 163 | setPermissions(this.town.permissions.toString()); 164 | break; 165 | case WILDS: 166 | setPermissions("denyAll"); 167 | break; 168 | case SPLEEF: 169 | setPermissions("denyAll"); 170 | break; 171 | } 172 | } 173 | 174 | public void setType(int typeId) { 175 | setType(TownBlockType.lookup(typeId)); 176 | } 177 | 178 | public void setType(String typeName) throws TownyException { 179 | if (typeName.equalsIgnoreCase("reset")) typeName = "default"; 180 | TownBlockType type = TownBlockType.lookup(typeName); 181 | if (type == null) 182 | throw new TownyException(TownySettings.getLangString("msg_err_not_block_type")); 183 | setType(type); 184 | } 185 | 186 | public boolean isHomeBlock() { 187 | try { 188 | return getTown().isHomeBlock(this); 189 | } catch (NotRegisteredException e) { 190 | return false; 191 | } 192 | } 193 | 194 | public void setX(int x) { 195 | this.x = x; 196 | } 197 | 198 | public int getX() { 199 | return x; 200 | } 201 | 202 | public void setZ(int z) { 203 | this.z = z; 204 | } 205 | 206 | public int getZ() { 207 | return z; 208 | } 209 | 210 | public Coord getCoord() { 211 | return new Coord(x, z); 212 | } 213 | 214 | public WorldCoord getWorldCoord() { 215 | return new WorldCoord(world, x, z); 216 | } 217 | 218 | /** 219 | * Is the TownBlock locked 220 | * 221 | * @return the locked 222 | */ 223 | public boolean isLocked() { 224 | return locked; 225 | } 226 | 227 | /** 228 | * @param locked is the to locked to set 229 | */ 230 | public void setLocked(boolean locked) { 231 | this.locked = locked; 232 | } 233 | 234 | public void setWorld(TownyWorld world) { 235 | this.world = world; 236 | } 237 | 238 | public TownyWorld getWorld() { 239 | return world; 240 | } 241 | 242 | @Override 243 | public boolean equals(Object obj) { 244 | if (obj == this) 245 | return true; 246 | if (!(obj instanceof TownBlock)) 247 | return false; 248 | 249 | TownBlock o = (TownBlock) obj; 250 | return this.getX() == o.getX() && this.getZ() == o.getZ() 251 | && this.getWorld() == o.getWorld(); 252 | } 253 | 254 | public void clear() { 255 | setTown(null); 256 | setResident(null); 257 | setWorld(null); 258 | } 259 | 260 | @Override 261 | public String toString() { 262 | return getWorld().getName() + " ("+getCoord()+")"; 263 | } 264 | 265 | public boolean isWarZone() { 266 | return getWorld().isWarZone(getCoord()); 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/TownyAsciiMap.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny; 2 | 3 | import org.bukkit.entity.Player; 4 | 5 | import com.palmergames.bukkit.towny.object.Coord; 6 | import com.palmergames.bukkit.towny.object.Nation; 7 | import com.palmergames.bukkit.towny.object.Resident; 8 | import com.palmergames.bukkit.towny.object.TownBlock; 9 | import com.palmergames.bukkit.towny.object.TownBlockType; 10 | import com.palmergames.bukkit.towny.object.TownyUniverse; 11 | import com.palmergames.bukkit.towny.object.TownyWorld; 12 | import com.palmergames.bukkit.util.ChatTools; 13 | import com.palmergames.bukkit.util.Colors; 14 | import com.palmergames.bukkit.util.Compass; 15 | 16 | public class TownyAsciiMap { 17 | public static final int lineWidth = 27; 18 | public static final int halfLineWidth = lineWidth / 2; 19 | public static final String[] help = { 20 | " " + Colors.Gray + "-" + Colors.LightGray + " = Unclaimed", 21 | " " + Colors.White + "+" + Colors.LightGray + " = Claimed", 22 | " " + Colors.White + "$" + Colors.LightGray + " = For sale", 23 | " " + Colors.LightGreen + "+" + Colors.LightGray + " = Your town", 24 | " " + Colors.Yellow + "+" + Colors.LightGray + " = Your plot", 25 | " " + Colors.Green + "+" + Colors.LightGray + " = Ally", 26 | " " + Colors.Red + "+" + Colors.LightGray + " = Enemy" 27 | }; 28 | 29 | public static String[] generateCompass(Player player) { 30 | Compass.Point dir = Compass.getCompassPointForDirection(player.getLocation().getYaw()); 31 | 32 | return new String[]{ 33 | Colors.Black + " ----- ", 34 | Colors.Black + " -" + (dir == Compass.Point.NW ? Colors.Gold + "\\" : "-") 35 | + (dir == Compass.Point.N ? Colors.Gold : Colors.White) + "N" 36 | + (dir == Compass.Point.NE ? Colors.Gold + "/" + Colors.Black : Colors.Black + "-") + "- ", 37 | Colors.Black + " -" + (dir == Compass.Point.W ? Colors.Gold + "W" : Colors.White + "W") + Colors.LightGray + "+" 38 | + (dir == Compass.Point.E ? Colors.Gold : Colors.White) + "E" + Colors.Black + "- ", 39 | Colors.Black + " -" + (dir == Compass.Point.SW ? Colors.Gold + "/" : "-") 40 | + (dir == Compass.Point.S ? Colors.Gold : Colors.White) + "S" 41 | + (dir == Compass.Point.SE ? Colors.Gold + "\\" + Colors.Black : Colors.Black + "-") + "- "}; 42 | } 43 | 44 | public static void generateAndSend(Towny plugin, Player player, int lineHeight) { 45 | // Collect Sample Data 46 | boolean hasTown = false; 47 | Resident resident; 48 | try { 49 | resident = TownyUniverse.getDataSource().getResident(player.getName()); 50 | if (resident.hasTown()) 51 | hasTown = true; 52 | } catch (TownyException x) { 53 | TownyMessaging.sendErrorMsg(player, x.getMessage()); 54 | return; 55 | } 56 | 57 | TownyWorld world; 58 | try { 59 | world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName()); 60 | } catch (NotRegisteredException e1) { 61 | TownyMessaging.sendErrorMsg(player, "You are not in a registered world."); 62 | return; 63 | } 64 | if (!world.isUsingTowny()) { 65 | TownyMessaging.sendErrorMsg(player, "This world is not using towny."); 66 | return; 67 | } 68 | Coord pos = Coord.parseCoord(plugin.getCache(player).getLastLocation()); 69 | 70 | // Generate Map 71 | int halfLineHeight = lineHeight / 2; 72 | String[][] townyMap = new String[lineWidth][lineHeight]; 73 | int x, y = 0; 74 | for (int tby = pos.getX() + (lineWidth-halfLineWidth-1); tby >= pos.getX() - halfLineWidth; tby--) { 75 | x = 0; 76 | for (int tbx = pos.getZ() - halfLineHeight; tbx <= pos.getZ() + (lineHeight-halfLineHeight-1); tbx++) { 77 | try { 78 | TownBlock townblock = world.getTownBlock(tby, tbx); 79 | //TODO: possibly claim outside of towns 80 | if (!townblock.hasTown()) 81 | throw new TownyException(); 82 | if (x == halfLineHeight && y == halfLineWidth) 83 | // location 84 | townyMap[y][x] = Colors.Gold; 85 | else if (hasTown) { 86 | if (resident.getTown() == townblock.getTown()) { 87 | // own town 88 | townyMap[y][x] = Colors.LightGreen; 89 | try { 90 | if (resident == townblock.getResident()) 91 | //own plot 92 | townyMap[y][x] = Colors.Yellow; 93 | } catch(NotRegisteredException e) { 94 | } 95 | } else if (resident.hasNation()) { 96 | if (resident.getTown().getNation().hasTown(townblock.getTown())) 97 | // towns 98 | townyMap[y][x] = Colors.Green; 99 | else if (townblock.getTown().hasNation()) { 100 | Nation nation = resident.getTown().getNation(); 101 | if (nation.hasAlly(townblock.getTown().getNation())) 102 | townyMap[y][x] = Colors.Green; 103 | else if (nation.hasEnemy(townblock.getTown().getNation())) 104 | // towns 105 | townyMap[y][x] = Colors.Red; 106 | else 107 | townyMap[y][x] = Colors.White; 108 | } else 109 | townyMap[y][x] = Colors.White; 110 | } else 111 | townyMap[y][x] = Colors.White; 112 | } else 113 | townyMap[y][x] = Colors.White; 114 | 115 | // Registered town block 116 | if (townblock.getPlotPrice() != -1) { 117 | // override the colour if it's a shop plot for sale 118 | if (townblock.getType().equals(TownBlockType.COMMERCIAL)) 119 | townyMap[y][x] = Colors.Blue; 120 | townyMap[y][x] += "$"; 121 | } else if (townblock.isHomeBlock()) 122 | townyMap[y][x] += "H"; 123 | else 124 | townyMap[y][x] += townblock.getType().getAsciiMapKey(); 125 | } catch (TownyException e) { 126 | if (x == halfLineHeight && y == halfLineWidth) 127 | townyMap[y][x] = Colors.Gold; 128 | else 129 | townyMap[y][x] = Colors.Gray; 130 | 131 | // Unregistered town block 132 | townyMap[y][x] += "-"; 133 | } 134 | x++; 135 | } 136 | y++; 137 | } 138 | 139 | String[] compass = generateCompass(player); 140 | 141 | // Output 142 | player.sendMessage(ChatTools.formatTitle("Towny Map " + Colors.White + "(" + pos.toString() + ")")); 143 | String line; 144 | int lineCount = 0; 145 | // Variables have been rotated to fit N/S/E/W properly 146 | for (int my = 0; my < lineHeight; my++) { 147 | line = compass[0]; 148 | if (lineCount < compass.length) 149 | line = compass[lineCount]; 150 | 151 | for (int mx = lineWidth-1; mx >= 0; mx--) 152 | line += townyMap[mx][my]; 153 | 154 | if (lineCount < help.length) 155 | line += help[lineCount]; 156 | 157 | player.sendMessage(line); 158 | lineCount++; 159 | } 160 | 161 | // Current town block data 162 | try { 163 | TownBlock townblock = world.getTownBlock(pos); 164 | TownyMessaging.sendMsg(player, ("Town: " + (townblock.hasTown() ? townblock.getTown().getName() : "None") + " : " 165 | + "Owner: " + (townblock.hasResident() ? townblock.getResident().getName() : "None"))); 166 | } catch (TownyException e) { 167 | //plugin.sendErrorMsg(player, e.getError()); 168 | // Send a blank line instead of an error, to keep the map position tidy. 169 | player.sendMessage (""); 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/object/PlotBlockData.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.object; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.World; 7 | import org.bukkit.block.Block; 8 | 9 | import com.palmergames.bukkit.towny.NotRegisteredException; 10 | import com.palmergames.bukkit.towny.TownySettings; 11 | import com.palmergames.bukkit.util.MinecraftTools; 12 | 13 | public class PlotBlockData { 14 | 15 | private int defaultVersion = 1; 16 | 17 | private String worldName; 18 | private int x, z, size, height, version; 19 | 20 | private List blockList = new ArrayList(); // Stores the original plot blocks 21 | private int blockListRestored; // counter for the next block to test 22 | 23 | public PlotBlockData(TownBlock townBlock) { 24 | setX(townBlock.getX()); 25 | setZ(townBlock.getZ()); 26 | setSize(TownySettings.getTownBlockSize()); 27 | this.worldName = townBlock.getWorld().getName(); 28 | this.setVersion(defaultVersion); 29 | try { 30 | setHeight(TownyUniverse.getPlugin().getServerWorld(worldName).getMaxHeight()-1); 31 | } catch (NotRegisteredException e) { 32 | setHeight(127); 33 | } 34 | this.blockListRestored = 0; 35 | } 36 | 37 | public void initialize() { 38 | Listblocks = getBlockArr(); 39 | if (blocks != null) { 40 | setBlockList(blocks); //fill array 41 | resetBlockListRestored(); 42 | } 43 | } 44 | 45 | /** 46 | * Fills an array with the current Block types from the plot. 47 | * 48 | * @return 49 | */ 50 | private List getBlockArr() { 51 | List list = new ArrayList(); 52 | Block block = null; 53 | 54 | 55 | try { 56 | World world = TownyUniverse.getPlugin().getServerWorld(worldName); 57 | /* 58 | if (!world.isChunkLoaded(MinecraftTools.calcChunk(getX()), MinecraftTools.calcChunk(getZ()))) { 59 | return null; 60 | } 61 | */ 62 | for (int z = 0; z < size; z++) 63 | for (int x = 0; x < size; x++) 64 | for (int y = height; y > 0; y--) { // Top down to account for falling blocks. 65 | block = world.getBlockAt((getX()*size) + x, y, (getZ()*size) + z); 66 | switch (defaultVersion) { 67 | 68 | case 1: 69 | list.add(block.getTypeId()); 70 | list.add((int) block.getData()); 71 | break; 72 | 73 | default: 74 | list.add(block.getTypeId()); 75 | } 76 | 77 | } 78 | 79 | } catch (NotRegisteredException e1) { 80 | // Failed to fetch world 81 | e1.printStackTrace(); 82 | } 83 | 84 | return list; 85 | } 86 | 87 | /** 88 | * Reverts an area to the stored image. 89 | * 90 | * @return true if there are more blocks to check. 91 | */ 92 | public boolean restoreNextBlock() { 93 | Block block = null; 94 | int x, y, z, blockId, reverse, scale; 95 | int worldx = getX()*size, worldz = getZ()*size; 96 | blockObject storedData; 97 | 98 | try { 99 | World world = TownyUniverse.getPlugin().getServerWorld(worldName); 100 | 101 | if (!world.isChunkLoaded(MinecraftTools.calcChunk(getX()), MinecraftTools.calcChunk(getZ()))) 102 | return true; 103 | 104 | //Scale for the number of elements 105 | switch (version) { 106 | 107 | case 1: 108 | scale = 2; 109 | break; 110 | 111 | default: 112 | scale = 1; 113 | } 114 | 115 | reverse = (blockList.size() - blockListRestored) / scale ; 116 | 117 | while (reverse > 0) { 118 | 119 | reverse--; //regen bottom up to stand a better chance of restoring tree's and plants. 120 | y = height - (reverse % height); 121 | x = (int)(reverse/height) % size; 122 | z = ((int)(reverse/height) / size) % size; 123 | 124 | block = world.getBlockAt(worldx + x, y, worldz + z); 125 | blockId = block.getTypeId(); 126 | storedData = getStoredBlockData((blockList.size()-1) - blockListRestored); 127 | 128 | // Increment based upon number of elements 129 | blockListRestored += scale; 130 | 131 | // If this block isn't correct, replace 132 | // and return as done. 133 | if ((blockId != storedData.getTypeID())) { 134 | if (!TownyUniverse.getDataSource().getWorld(worldName).isPlotManagementIgnoreIds(storedData.getTypeID())) { 135 | 136 | //System.out.print("regen x: " + x + " y: " + y + " z: " + z + " ID: " + blockId); 137 | 138 | //restore based upon version 139 | switch (version) { 140 | 141 | case 1: 142 | block.setTypeIdAndData(storedData.getTypeID(), storedData.getData(), false); 143 | 144 | break; 145 | default: 146 | block.setTypeId(storedData.getTypeID()); 147 | } 148 | 149 | } else 150 | block.setTypeId(0); 151 | 152 | return true; 153 | } 154 | } 155 | } catch (NotRegisteredException e1) { 156 | // Failed to get world. 157 | e1.printStackTrace(); 158 | } 159 | 160 | // reset as we are finished with the regeneration 161 | resetBlockListRestored(); 162 | return false; 163 | } 164 | 165 | private blockObject getStoredBlockData(int index) { 166 | //return based upon version 167 | switch (version) { 168 | 169 | case 1: 170 | return new blockObject(blockList.get(index-1), (byte)(blockList.get(index) & 0xff)); 171 | 172 | default: 173 | return new blockObject(blockList.get(index), (byte) 0); 174 | } 175 | 176 | } 177 | 178 | public int getX() { 179 | return x; 180 | } 181 | public void setX(int x) { 182 | this.x = x; 183 | } 184 | 185 | public int getZ() { 186 | return z; 187 | } 188 | public void setZ(int z) { 189 | this.z = z; 190 | } 191 | 192 | public int getSize() { 193 | return size; 194 | } 195 | public void setSize(int size) { 196 | this.size = size; 197 | } 198 | 199 | public int getHeight() { 200 | return height; 201 | } 202 | 203 | public void setHeight(int height) { 204 | this.height = height; 205 | } 206 | 207 | public String getWorldName() { 208 | return worldName; 209 | } 210 | 211 | /** 212 | * @return the version 213 | */ 214 | public int getVersion() { 215 | return version; 216 | } 217 | 218 | /** 219 | * @param version the version to set 220 | */ 221 | public void setVersion(int version) { 222 | this.version = version; 223 | } 224 | 225 | /** 226 | * @return the blockList 227 | */ 228 | public List getBlockList() { 229 | return blockList; 230 | } 231 | 232 | /** 233 | * fills the BlockList 234 | * 235 | * @param blockList 236 | */ 237 | public void setBlockList(List blockList) { 238 | this.blockList = blockList; 239 | } 240 | 241 | /** 242 | * fills BlockListRestored with zero's to indicate 243 | * no blocks have been restored yet 244 | */ 245 | public void resetBlockListRestored() { 246 | blockListRestored = 0; 247 | } 248 | 249 | 250 | } -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/tasks/TownClaim.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.tasks; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.entity.Player; 9 | 10 | import com.palmergames.bukkit.towny.AlreadyRegisteredException; 11 | import com.palmergames.bukkit.towny.NotRegisteredException; 12 | import com.palmergames.bukkit.towny.Towny; 13 | import com.palmergames.bukkit.towny.TownyException; 14 | import com.palmergames.bukkit.towny.TownyMessaging; 15 | import com.palmergames.bukkit.towny.TownySettings; 16 | import com.palmergames.bukkit.towny.object.PlotBlockData; 17 | import com.palmergames.bukkit.towny.object.Town; 18 | import com.palmergames.bukkit.towny.object.TownBlock; 19 | import com.palmergames.bukkit.towny.object.TownyRegenAPI; 20 | import com.palmergames.bukkit.towny.object.TownyUniverse; 21 | import com.palmergames.bukkit.towny.object.TownyWorld; 22 | import com.palmergames.bukkit.towny.object.WorldCoord; 23 | 24 | /** 25 | * @author ElgarL 26 | * 27 | */ 28 | public class TownClaim extends Thread { 29 | 30 | Towny plugin; 31 | volatile Player player; 32 | volatile Town town; 33 | List selection; 34 | boolean claim, forced; 35 | 36 | /** 37 | * @param plugin reference to towny 38 | * @param player Doing the claiming, or null 39 | * @param town The claiming town 40 | * @param selection List of WoorldCoords to claim/unclaim 41 | * @param claim or unclaim 42 | * @param forced admin forced claim/unclaim 43 | */ 44 | public TownClaim(Towny plugin, Player player, Town town, List selection, boolean claim, boolean forced) { 45 | super(); 46 | this.plugin = plugin; 47 | this.player = player; 48 | this.town = town; 49 | this.selection = selection; 50 | this.claim = claim; 51 | this.forced = forced; 52 | this.setPriority(MIN_PRIORITY); 53 | } 54 | 55 | @Override 56 | public void run() { 57 | 58 | List worlds = new ArrayList(); 59 | List towns = new ArrayList(); 60 | TownyWorld world; 61 | 62 | if (player != null) TownyMessaging.sendMsg(player, "Processing " + ((claim) ? "Town Claim..." : "Town unclaim...")); 63 | 64 | if (selection != null) { 65 | 66 | for (WorldCoord worldCoord : selection) { 67 | 68 | try { 69 | world = TownyUniverse.getDataSource().getWorld(worldCoord.getWorld().getName()); 70 | if (!worlds.contains(world)) worlds.add(world); 71 | 72 | if (claim) 73 | townClaim(town, worldCoord); 74 | else { 75 | this.town = worldCoord.getTownBlock().getTown(); 76 | townUnclaim(town, worldCoord, forced); 77 | } 78 | 79 | if (!towns.contains(town)) towns.add(town); 80 | 81 | } catch (NotRegisteredException e) { 82 | // Invalid world 83 | TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_err_not_configured")); 84 | } catch (TownyException x) { 85 | TownyMessaging.sendErrorMsg(player, x.getMessage()); 86 | } 87 | 88 | } 89 | 90 | } else if (!claim){ 91 | 92 | townUnclaimAll(town); 93 | } 94 | 95 | if (!towns.isEmpty()) 96 | for (Town test : towns) 97 | TownyUniverse.getDataSource().saveTown(test); 98 | 99 | if (!worlds.isEmpty()) 100 | for (TownyWorld test : worlds) 101 | TownyUniverse.getDataSource().saveWorld(test); 102 | 103 | plugin.updateCache(); 104 | 105 | if (player != null) { 106 | if (claim) { 107 | TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_annexed_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0])))); 108 | if (town.getWorld().isUsingPlotManagementRevert()) 109 | TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked")); 110 | } else if (forced) { 111 | TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_admin_unclaim_area"), (selection.size() > 5) ? "Total TownBlocks: " + selection.size() : Arrays.toString(selection.toArray(new WorldCoord[0])))); 112 | if (town.getWorld().isUsingPlotManagementRevert()) 113 | TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_wait_locked")); 114 | } 115 | } 116 | 117 | 118 | } 119 | 120 | private void townClaim(Town town, WorldCoord worldCoord) throws TownyException { 121 | try { 122 | TownBlock townBlock = worldCoord.getTownBlock(); 123 | try { 124 | throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), townBlock.getTown().getName())); 125 | } catch (NotRegisteredException e) { 126 | throw new AlreadyRegisteredException(TownySettings.getLangString("msg_already_claimed_2")); 127 | } 128 | } catch (NotRegisteredException e) { 129 | TownBlock townBlock = worldCoord.getWorld().newTownBlock(worldCoord); 130 | townBlock.setTown(town); 131 | if (!town.hasHomeBlock()) 132 | town.setHomeBlock(townBlock); 133 | 134 | // Set the plot permissions to mirror the towns. 135 | townBlock.setType(townBlock.getType()); 136 | TownyUniverse.getDataSource().saveTownBlock(townBlock); 137 | 138 | if (town.getWorld().isUsingPlotManagementRevert()) { 139 | PlotBlockData plotChunk = TownyRegenAPI.getPlotChunk(townBlock); 140 | if (plotChunk != null) { 141 | TownyRegenAPI.deletePlotChunk(plotChunk); // just claimed so stop regeneration. 142 | townBlock.setLocked(false); 143 | } else { 144 | //plotChunk = new PlotBlockData(townBlock); // Not regenerating so create a new snapshot. 145 | //plotChunk.initialize(); 146 | 147 | // Push the TownBlock location to the queue for a snapshot. 148 | TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord()); 149 | townBlock.setLocked(true); 150 | 151 | TownyUniverse.getDataSource().saveTownBlock(townBlock); 152 | } 153 | //if (!plotChunk.getBlockList().isEmpty() && !(plotChunk.getBlockList() == null)) 154 | // TownyRegenAPI.addPlotChunkSnapshot(plotChunk); // Save a snapshot. 155 | 156 | plotChunk = null; 157 | } 158 | } 159 | } 160 | 161 | private void townUnclaim(Town town, WorldCoord worldCoord, boolean force) throws TownyException { 162 | try { 163 | final TownBlock townBlock = worldCoord.getTownBlock(); 164 | if (town != townBlock.getTown() && !force) 165 | throw new TownyException(TownySettings.getLangString("msg_area_not_own")); 166 | 167 | Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { 168 | 169 | @Override 170 | public void run() { 171 | TownyUniverse.getDataSource().removeTownBlock(townBlock); 172 | }}, 1); 173 | 174 | } catch (NotRegisteredException e) { 175 | throw new TownyException(TownySettings.getLangString("msg_not_claimed_1")); 176 | } 177 | } 178 | 179 | private void townUnclaimAll(final Town town) { 180 | Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { 181 | 182 | @Override 183 | public void run() { 184 | TownyUniverse.getDataSource().removeTownBlocks(town); 185 | TownyMessaging.sendTownMessage(town, TownySettings.getLangString("msg_abandoned_area_1")); 186 | }}, 1); 187 | 188 | } 189 | } 190 | -------------------------------------------------------------------------------- /src/com/palmergames/bukkit/towny/permissions/PEXSource.java: -------------------------------------------------------------------------------- 1 | package com.palmergames.bukkit.towny.permissions; 2 | 3 | 4 | import java.util.Arrays; 5 | 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.CustomEventListener; 8 | import org.bukkit.event.Event; 9 | import org.bukkit.event.Event.Priority; 10 | import org.bukkit.plugin.Plugin; 11 | 12 | import ru.tehkode.permissions.PermissionEntity; 13 | import ru.tehkode.permissions.PermissionGroup; 14 | import ru.tehkode.permissions.PermissionManager; 15 | import ru.tehkode.permissions.PermissionUser; 16 | import ru.tehkode.permissions.bukkit.PermissionsEx; 17 | import ru.tehkode.permissions.events.PermissionEntityEvent; 18 | import ru.tehkode.permissions.events.PermissionSystemEvent; 19 | 20 | import com.palmergames.bukkit.towny.NotRegisteredException; 21 | import com.palmergames.bukkit.towny.Towny; 22 | import com.palmergames.bukkit.towny.TownySettings; 23 | import com.palmergames.bukkit.towny.object.Resident; 24 | import com.palmergames.bukkit.towny.object.TownyUniverse; 25 | 26 | 27 | /** 28 | * @author ElgarL 29 | * 30 | */ 31 | public class PEXSource extends TownyPermissionSource { 32 | 33 | public PEXSource(Towny towny, Plugin test) { 34 | this.pex = (PermissionsEx)test; 35 | this.plugin = towny; 36 | 37 | plugin.getServer().getPluginManager().registerEvent(Event.Type.CUSTOM_EVENT, new PEXCustomEventListener(), Priority.High, plugin); 38 | } 39 | 40 | /** getPermissionNode 41 | * 42 | * returns the specified prefix/suffix nodes from permissionsEX 43 | * 44 | * @param resident 45 | * @param node 46 | * @return String of the prefix or suffix 47 | */ 48 | @Override 49 | public String getPrefixSuffix(Resident resident, String node) { 50 | 51 | String group = "", user = ""; 52 | Player player = plugin.getServer().getPlayer(resident.getName()); 53 | 54 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 55 | 56 | if (node == "prefix") { 57 | group = pexPM.getUser(player).getPrefix(player.getWorld().getName()); 58 | user = pexPM.getUser(player).getOwnPrefix(); 59 | } else if (node == "suffix") { 60 | group = pexPM.getUser(player).getSuffix(player.getWorld().getName()); 61 | user = pexPM.getUser(player).getOwnSuffix(); 62 | } 63 | if (group == null) group = ""; 64 | if (user == null) user = ""; 65 | 66 | if (!group.equals(user)) 67 | user = group + user; 68 | user = TownySettings.parseSingleLineString(user); 69 | 70 | return user; 71 | 72 | } 73 | 74 | /** 75 | * 76 | * @param playerName 77 | * @param node 78 | * @return -1 = can't find 79 | */ 80 | @Override 81 | public int getGroupPermissionIntNode(String playerName, String node) { 82 | Player player = plugin.getServer().getPlayer(playerName); 83 | String worldName = player.getWorld().getName(); 84 | 85 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 86 | 87 | //return pexPM.getUser(player).getOptionInteger(node, worldName, -1); 88 | 89 | String result = pexPM.getUser(player).getOption(node, worldName); 90 | 91 | try { 92 | return Integer.parseInt(result); 93 | } catch (NumberFormatException e) { 94 | return -1; 95 | } 96 | 97 | } 98 | 99 | /** 100 | * 101 | * @param playerName 102 | * @param node 103 | * @return empty = can't find 104 | */ 105 | @Override 106 | public String getPlayerPermissionStringNode(String playerName, String node) { 107 | Player player = plugin.getServer().getPlayer(playerName); 108 | String worldName = player.getWorld().getName(); 109 | 110 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 111 | 112 | //return pexPM.getUser(player).getOptionInteger(node, worldName, -1); 113 | String result = pexPM.getUser(player).getOption(node, worldName); 114 | if (result != null) 115 | return result; 116 | 117 | return ""; 118 | 119 | } 120 | 121 | /** hasPermission 122 | * 123 | * returns if a player has a certain permission node. 124 | * 125 | * @param player 126 | * @param node 127 | * @return true if Op or has the permission node. 128 | */ 129 | @Override 130 | public boolean hasPermission(Player player, String node) { 131 | 132 | if (player.isOp()) 133 | return true; 134 | 135 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 136 | 137 | return pexPM.getUser(player).has(node); 138 | } 139 | 140 | /** 141 | * Returns the players Group name. 142 | * 143 | * @param player 144 | * @return Name of the players group 145 | */ 146 | @Override 147 | public String getPlayerGroup(Player player) { 148 | 149 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 150 | 151 | return pexPM.getUser(player).getGroupsNames()[0]; 152 | 153 | } 154 | 155 | /** 156 | * Returns an array of Groups this player is a member of. 157 | * 158 | * @param player 159 | * @return Array of groups for this player 160 | */ 161 | public PermissionGroup[] getPlayerGroups(Player player) { 162 | 163 | PermissionManager pexPM = PermissionsEx.getPermissionManager(); 164 | 165 | return pexPM.getUser(player).getGroups(); 166 | 167 | } 168 | 169 | protected class PEXCustomEventListener extends CustomEventListener { 170 | 171 | public PEXCustomEventListener() { 172 | } 173 | 174 | @Override 175 | public void onCustomEvent(Event event) { 176 | 177 | Resident resident = null; 178 | Player player = null; 179 | 180 | try { 181 | if (event instanceof PermissionEntityEvent) { 182 | if (PermissionEventEnums.PEXEntity_Action.valueOf(event.getEventName()) != null) { 183 | PermissionEntityEvent EntityEvent = (PermissionEntityEvent) event; 184 | PermissionEntity entity = EntityEvent.getEntity(); 185 | if (entity instanceof PermissionGroup) { 186 | PermissionGroup group = (PermissionGroup)entity; 187 | 188 | // Update all players who are in this group. 189 | for (Player toUpdate : TownyUniverse.getOnlinePlayers()) { 190 | if (Arrays.asList(getPlayerGroups(toUpdate)).contains(group)) { 191 | //setup default modes 192 | String[] modes = getPlayerPermissionStringNode(toUpdate.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 193 | plugin.setPlayerMode(player, modes, false); 194 | } 195 | } 196 | 197 | } else if (entity instanceof PermissionUser) { 198 | 199 | try { 200 | resident = TownyUniverse.getDataSource().getResident(((PermissionUser)entity).getName()); 201 | player = plugin.getServer().getPlayerExact(resident.getName()); 202 | if (player != null) { 203 | //setup default modes for this player. 204 | String[] modes = getPlayerPermissionStringNode(player.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 205 | plugin.setPlayerMode(player, modes, false); 206 | } 207 | } catch (NotRegisteredException x) { 208 | } 209 | } 210 | } 211 | 212 | } else if (event instanceof PermissionSystemEvent) { 213 | if (PermissionEventEnums.PEXSystem_Action.valueOf(event.getEventName()) != null) { 214 | // Update all players. 215 | for (Player toUpdate : TownyUniverse.getOnlinePlayers()) { 216 | //setup default modes 217 | String[] modes = getPlayerPermissionStringNode(toUpdate.getName(), PermissionNodes.TOWNY_DEFAULT_MODES.getNode()).split(","); 218 | plugin.setPlayerMode(player, modes, false); 219 | } 220 | } 221 | 222 | } 223 | } catch (IllegalArgumentException ex) { 224 | // We are not looking for this event type. 225 | } 226 | } 227 | } 228 | 229 | } --------------------------------------------------------------------------------