From 46a814a11ec6370b057b5d9447d23f4374f03fc5 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 7 Feb 2011 21:42:14 +0100 Subject: [PATCH] This would be v1.0 beta2. Just live testing on mcteam.org left to do. --- README.md | 2 +- plugin.yml | 2 +- src/com/bukkit/mcteam/factions/Commands.java | 55 ++++++++++++------- src/com/bukkit/mcteam/factions/Factions.java | 3 + .../mcteam/factions/entities/Board.java | 5 +- .../bukkit/mcteam/factions/entities/Conf.java | 35 +++++------- .../bukkit/mcteam/factions/entities/EM.java | 7 ++- .../mcteam/factions/entities/Faction.java | 10 +--- .../mcteam/factions/entities/Follower.java | 27 --------- .../FactionsBlockListener.java | 5 +- .../FactionsEntityListener.java | 3 +- .../FactionsPlayerListener.java | 4 +- .../mcteam/factions/struct/Relation.java | 19 ------- 13 files changed, 71 insertions(+), 106 deletions(-) rename src/com/bukkit/mcteam/factions/{ => listeners}/FactionsBlockListener.java (96%) rename src/com/bukkit/mcteam/factions/{ => listeners}/FactionsEntityListener.java (97%) rename src/com/bukkit/mcteam/factions/{ => listeners}/FactionsPlayerListener.java (95%) diff --git a/README.md b/README.md index a9807f4d..935612b2 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ You can download it here: [http://bamboo.lukegb.com/browse/BUKKIT-BUKKITMAIN/](h You will also need Google GSON in your build path.
You can download it here: [http://code.google.com/p/google-gson/](http://code.google.com/p/google-gson/)
-OR you can use the file in this repo `/packaging/gson.jar`
+OR you can use the file in this repo `/packaging/your_minecraft_server/gson.jar`
However you won't get javadocs and source that way. You will need to include the MANIFEST.MF and plugin.yml in your jar. All bukkit plugins need a plugin.yml and the MANIFEST.MF is needed for the plugin to find the gson.jar (wich should be in the same folder as the main server jar when running the server). \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 63617f4c..d146cc62 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,3 +1,3 @@ name: Factions -version: 1.0 beta1 +version: 1.0 beta2 main: com.bukkit.mcteam.factions.Factions \ No newline at end of file diff --git a/src/com/bukkit/mcteam/factions/Commands.java b/src/com/bukkit/mcteam/factions/Commands.java index 62148997..ef340d03 100644 --- a/src/com/bukkit/mcteam/factions/Commands.java +++ b/src/com/bukkit/mcteam/factions/Commands.java @@ -24,7 +24,7 @@ public class Commands { pageLines.add(TextUtil.commandHelp(Conf.aliasHelp, "[page]", "Display this, or the next help page")); pageLines.add(TextUtil.commandHelp(Conf.aliasList, "", "List all factions")); pageLines.add(TextUtil.commandHelp(Conf.aliasShow, "*[faction name]", "Show faction information")); // TODO display relations! - pageLines.add(TextUtil.commandHelp(Conf.aliasMap, "*[on|off]", "Show territory map, set optional auto update.")); // TODO COMPASS + pageLines.add(TextUtil.commandHelp(Conf.aliasMap, "*[on|off]", "Show territory map, set optional auto update.")); pageLines.add(TextUtil.commandHelp(Conf.aliasJoin, "[faction name]", "Join a faction")); pageLines.add(TextUtil.commandHelp(Conf.aliasLeave, "", "Leave your faction")); pageLines.add(TextUtil.commandHelp(Conf.aliasCreate, "[faction name]", "Create new faction")); @@ -38,8 +38,8 @@ public class Commands { pageLines.add(TextUtil.commandHelp(Conf.aliasInvite, "[player name]", "Invite player")); pageLines.add(TextUtil.commandHelp(Conf.aliasDeinvite, "[player name]", "Remove a pending invitation")); pageLines.add(TextUtil.commandHelp(Conf.aliasKick, "[player name]", "Kick a player from the faction")); - pageLines.add(TextUtil.commandHelp(Conf.aliasModerator, "[player name]", "Give or revoke moderator rights")); // TODO - pageLines.add(TextUtil.commandHelp(Conf.aliasAdmin, "[player name]", "Hand over your admin rights")); // TODO + pageLines.add(TextUtil.commandHelp(Conf.aliasModerator, "[player name]", "Give or revoke moderator rights")); + pageLines.add(TextUtil.commandHelp(Conf.aliasAdmin, "[player name]", "Hand over your admin rights")); pageLines.add(TextUtil.commandHelp(Conf.aliasClaim, "", "Claim the land where you are standing")); pageLines.add(TextUtil.commandHelp(Conf.aliasUnclaim, "", "Unclaim the land where you are standing")); @@ -213,9 +213,7 @@ public class Commands { } else if (Conf.aliasVersion.contains(command)) { version(me); } else { - //me.sendMessage(Conf.colorSystem+"Unknown faction command"+Conf.colorCommand+" "+command); me.sendMessage(Conf.colorSystem+"Unknown faction command"+Conf.colorCommand+" "+command); - //me.getPlayer().sendMessage(TextUtil.repeat(tokens.get(0), Integer.parseInt(tokens.get(1)))); } } @@ -243,14 +241,14 @@ public class Commands { me.sendMessage(errors); if (errors.size() == 0) { - faction.sendMessage(me.getFullName(faction)+Conf.colorAction+" left your faction."); + faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" left your faction."); me.sendMessage("You left "+faction.getName(me)); } if (faction.getFollowersAll().size() == 0) { // Remove this faction for (Follower follower : Follower.getAll()) { - follower.sendMessage(Conf.colorAction+"The faction "+faction.getName(follower)+Conf.colorAction+" was disbandoned."); + follower.sendMessage(Conf.colorSystem+"The faction "+faction.getName(follower)+Conf.colorSystem+" was disbandoned."); } EM.factionDelete(faction.id); } @@ -268,18 +266,38 @@ public class Commands { if (errors.size() > 0) { faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" tried to join your faction."); } else { - me.sendMessage(Conf.colorAction+"You successfully joined "+faction.getName(me)); - faction.sendMessage(me.getFullName(faction)+Conf.colorAction+" joined your faction."); + me.sendMessage(Conf.colorSystem+"You successfully joined "+faction.getName(me)); + faction.sendMessage(me.getFullName(faction)+Conf.colorSystem+" joined your faction."); } } - // TODO MOVE OUT public static void create(Follower me, String name) { - ArrayList errors = me.createFaction(name); - me.sendMessage(errors); - - if (errors.size() == 0) { - me.sendMessage(Conf.colorAction+"Faction created!"); + ArrayList errors = new ArrayList(); + + if (me.factionId != 0) { + errors.add(Conf.colorSystem+"You must leave your current faction first."); + } + + if (Faction.isNameTaken(name)) { + errors.add(Conf.colorSystem+"That name is already in use."); + } + + errors.addAll(Faction.validateName(name)); + + if (errors.size() > 0) { + me.sendMessage(errors); + return; + } + + Faction faction = EM.factionCreate(); + faction.setName(name); + faction.save(); + me.join(faction); + me.role = Role.ADMIN; + me.save(); + + for (Follower follower : Follower.getAll()) { + follower.sendMessage(me.getFullName(follower)+Conf.colorSystem+" created a new faction "+faction.getName(follower)); } } @@ -392,11 +410,11 @@ public class Commands { if (Conf.aliasTrue.contains(mapAutoUpdating.toLowerCase())) { // Turn on me.setMapAutoUpdating(true); - me.sendMessage(Conf.colorAction + "Map auto update ENABLED."); + me.sendMessage(Conf.colorSystem + "Map auto update ENABLED."); } else { // Turn off me.setMapAutoUpdating(false); - me.sendMessage(Conf.colorAction + "Map auto update DISABLED."); + me.sendMessage(Conf.colorSystem + "Map auto update DISABLED."); } } else { me.sendMessage(Board.getMap(me.getFaction(), Coord.from(me), me.getPlayer().getLocation().getYaw()), false); @@ -416,7 +434,6 @@ public class Commands { ChatColor relationColor = me.getRelationColor(follower); follower.sendMessage(relationColor+me.getFullName()+Conf.colorSystem+" invited you to "+relationColor+me.getFaction().getName()); me.getFaction().sendMessage(me.getFullName(me)+Conf.colorSystem+" invited "+follower.getFullName(me)+Conf.colorSystem+" to your faction."); - //me.sendMessage(Conf.colorAction+"You invited "+relationColor+follower.getFullName()+Conf.colorAction+" to "+Relation.MEMBER.getColor()+me.getFaction().getName()); } } @@ -690,7 +707,7 @@ public class Commands { me.getFaction().setDescription(desc); - me.sendMessage(Conf.colorAction+"The new decription was set :D"); + me.sendMessage(Conf.colorSystem+"The new decription was set :D"); // Broadcast the description to everyone for (Follower follower : EM.followerGetAll()) { diff --git a/src/com/bukkit/mcteam/factions/Factions.java b/src/com/bukkit/mcteam/factions/Factions.java index 7313ddf1..13c5ec55 100644 --- a/src/com/bukkit/mcteam/factions/Factions.java +++ b/src/com/bukkit/mcteam/factions/Factions.java @@ -10,6 +10,9 @@ import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import com.bukkit.mcteam.factions.entities.*; +import com.bukkit.mcteam.factions.listeners.FactionsBlockListener; +import com.bukkit.mcteam.factions.listeners.FactionsEntityListener; +import com.bukkit.mcteam.factions.listeners.FactionsPlayerListener; import com.bukkit.mcteam.factions.util.Log; public class Factions extends JavaPlugin { diff --git a/src/com/bukkit/mcteam/factions/entities/Board.java b/src/com/bukkit/mcteam/factions/entities/Board.java index 46c46c22..0116f165 100644 --- a/src/com/bukkit/mcteam/factions/entities/Board.java +++ b/src/com/bukkit/mcteam/factions/entities/Board.java @@ -114,10 +114,7 @@ public class Board { // Get the compass ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, Conf.colorChrome); - // Pad the compass some - asciiCompass.set(0, asciiCompass.get(0)); - asciiCompass.set(1, asciiCompass.get(1)); - asciiCompass.set(2, asciiCompass.get(2)); + // Add the compass ret.set(1, asciiCompass.get(0)+ret.get(1).substring(3*3)); ret.set(2, asciiCompass.get(1)+ret.get(2).substring(3*3)); diff --git a/src/com/bukkit/mcteam/factions/entities/Conf.java b/src/com/bukkit/mcteam/factions/entities/Conf.java index 9aed33cd..3fb5346b 100644 --- a/src/com/bukkit/mcteam/factions/entities/Conf.java +++ b/src/com/bukkit/mcteam/factions/entities/Conf.java @@ -30,7 +30,6 @@ public class Conf { public static ChatColor colorEnemy; public static ChatColor colorSystem; - public static ChatColor colorAction; public static ChatColor colorChrome; public static ChatColor colorCommand; public static ChatColor colorParameter; @@ -43,8 +42,6 @@ public class Conf { public static List aliasShow = new ArrayList(); public static List aliasMap = new ArrayList(); - public static List aliasHere = new ArrayList(); - public static List aliasJoin = new ArrayList(); public static List aliasLeave = new ArrayList(); @@ -76,11 +73,9 @@ public class Conf { public static List aliasTrue = new ArrayList(); // Power - public static double powerPerLand; public static double powerPerPlayer; public static double powerPerMinute; // Default health rate public static double powerPerDeath; - public static double powerDefaultBonus; // Protected blocks public static List territoryProtectedMaterials = new ArrayList(); @@ -89,15 +84,18 @@ public class Conf { logThreshold = 10; prefixAdmin = "**"; prefixMod = "*"; - factionNameMinLength = 3; - factionNameMaxLength = 40; + useRelationColoredChat = true; - mapHeight = 8; - mapWidth = 49; + powerPerPlayer = 10; // One player has 10 power + powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power + powerPerDeath = 2; //A death makes you loose 2 power territoryShieldFactor = 0.5; - - useRelationColoredChat = true; + + territoryProtectedMaterials.add(Material.WOODEN_DOOR); + territoryProtectedMaterials.add(Material.DISPENSER); + territoryProtectedMaterials.add(Material.CHEST); + territoryProtectedMaterials.add(Material.FURNACE); colorMember = ChatColor.GREEN; colorAlly = ChatColor.LIGHT_PURPLE; @@ -105,7 +103,6 @@ public class Conf { colorEnemy = ChatColor.RED; colorSystem = ChatColor.YELLOW; - colorAction = ChatColor.LIGHT_PURPLE; colorChrome = ChatColor.GOLD; colorCommand = ChatColor.AQUA; colorParameter = ChatColor.DARK_AQUA; @@ -128,7 +125,6 @@ public class Conf { aliasShow.add("who"); aliasMap.add("map"); - aliasHere.add("here"); aliasJoin.add("join"); @@ -177,16 +173,11 @@ public class Conf { aliasTrue.add("on"); aliasTrue.add("+"); - powerPerLand = 1; // 1 power grants one land Perhaps this should not even be a config value... - powerPerPlayer = 10; // One player has 10 power - powerPerMinute = 0.2; // Default health rate... it takes 5 min to heal one power - powerPerDeath = 2; //A death makes you loose 2 power - powerDefaultBonus = 0; //A faction normally has a power bonus + factionNameMinLength = 3; + factionNameMaxLength = 40; - territoryProtectedMaterials.add(Material.WOODEN_DOOR); - territoryProtectedMaterials.add(Material.DISPENSER); - territoryProtectedMaterials.add(Material.CHEST); - territoryProtectedMaterials.add(Material.FURNACE); + mapHeight = 8; + mapWidth = 49; } //----------------------------------------------// diff --git a/src/com/bukkit/mcteam/factions/entities/EM.java b/src/com/bukkit/mcteam/factions/entities/EM.java index 2f898a64..2ac486ff 100644 --- a/src/com/bukkit/mcteam/factions/entities/EM.java +++ b/src/com/bukkit/mcteam/factions/entities/EM.java @@ -36,6 +36,7 @@ public class EM { .create(); public static void loadAll() { + folderBase.mkdirs(); configLoad(); Log.threshold = Conf.logThreshold; boardLoad(); @@ -59,11 +60,12 @@ public class EM { } } Log.info("No conf.json found! Creating a new one with the default values"); - //configSave(); // FOR DEBUGGING... + configSave(); return true; } public static boolean configSave() { + folderBase.mkdirs(); try { DiscUtil.write(fileConfig, gson.toJson(new Conf())); Log.debug("Config was saved to disc"); @@ -91,11 +93,12 @@ public class EM { } } Log.info("No board.json found! Creating a new one with the default values"); - //boardSave(); // FOR DEBUGGING... + boardSave(); return true; } public static boolean boardSave() { + folderBase.mkdirs(); try { DiscUtil.write(fileBoard, gson.toJson(new Board())); Log.debug("Board was saved to disc"); diff --git a/src/com/bukkit/mcteam/factions/entities/Faction.java b/src/com/bukkit/mcteam/factions/entities/Faction.java index 5b2c8e63..4a8e109d 100644 --- a/src/com/bukkit/mcteam/factions/entities/Faction.java +++ b/src/com/bukkit/mcteam/factions/entities/Faction.java @@ -72,19 +72,15 @@ public class Faction { // Power //----------------------------------------------// public double getPower() { - double ret = this.getPowerBonus(); + double ret = 0; for (Follower follower : this.getFollowersAll()) { ret += follower.getPower(); } return ret; } - public double getPowerBonus() { - return Conf.powerDefaultBonus; // TODO this could be modified by commands later on - } - public double getPowerMax() { - double ret = this.getPowerBonus(); + double ret = 0; for (Follower follower : this.getFollowersAll()) { ret += follower.getPowerMax(); } @@ -104,7 +100,7 @@ public class Faction { } public double getLandMax() { - return this.getPower() / Conf.powerPerLand; + return this.getPower(); } public int getLandMaxRounded() { diff --git a/src/com/bukkit/mcteam/factions/entities/Follower.java b/src/com/bukkit/mcteam/factions/entities/Follower.java index 3bbc013c..85ddb88a 100644 --- a/src/com/bukkit/mcteam/factions/entities/Follower.java +++ b/src/com/bukkit/mcteam/factions/entities/Follower.java @@ -203,33 +203,6 @@ public class Follower { return errors; } - public ArrayList createFaction(String name) { - ArrayList errors = new ArrayList(); - - if (this.factionId != 0) { - errors.add(Conf.colorSystem+"You must leave your current faction first."); - } - - if (Faction.isNameTaken(name)) { - errors.add(Conf.colorSystem+"That name is already in use."); - } - - errors.addAll(Faction.validateName(name)); - - if (errors.size() > 0) { - return errors; - } - - Faction faction = EM.factionCreate(); - faction.setName(name); - faction.save(); - this.join(faction); - this.role = Role.ADMIN; - this.save(); - - return errors; - } - public ArrayList invite(Follower follower) { ArrayList errors = new ArrayList(); diff --git a/src/com/bukkit/mcteam/factions/FactionsBlockListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java similarity index 96% rename from src/com/bukkit/mcteam/factions/FactionsBlockListener.java rename to src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java index 66b1be6e..ef4c7c07 100644 --- a/src/com/bukkit/mcteam/factions/FactionsBlockListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsBlockListener.java @@ -1,4 +1,4 @@ -package com.bukkit.mcteam.factions; +package com.bukkit.mcteam.factions.listeners; import org.bukkit.Material; import org.bukkit.block.Block; @@ -9,8 +9,9 @@ import org.bukkit.event.block.BlockInteractEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; +import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.entities.*; -import com.bukkit.mcteam.factions.util.TextUtil; +import com.bukkit.mcteam.factions.util.*; public class FactionsBlockListener extends BlockListener { public Factions plugin; diff --git a/src/com/bukkit/mcteam/factions/FactionsEntityListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java similarity index 97% rename from src/com/bukkit/mcteam/factions/FactionsEntityListener.java rename to src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java index 986f7e27..10148737 100644 --- a/src/com/bukkit/mcteam/factions/FactionsEntityListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsEntityListener.java @@ -1,4 +1,4 @@ -package com.bukkit.mcteam.factions; +package com.bukkit.mcteam.factions.listeners; import java.text.DecimalFormat; @@ -9,6 +9,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityListener; +import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.entities.Conf; import com.bukkit.mcteam.factions.entities.Follower; import com.bukkit.mcteam.factions.struct.Relation; diff --git a/src/com/bukkit/mcteam/factions/FactionsPlayerListener.java b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java similarity index 95% rename from src/com/bukkit/mcteam/factions/FactionsPlayerListener.java rename to src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java index 63690634..2b9fbfd3 100644 --- a/src/com/bukkit/mcteam/factions/FactionsPlayerListener.java +++ b/src/com/bukkit/mcteam/factions/listeners/FactionsPlayerListener.java @@ -1,4 +1,4 @@ -package com.bukkit.mcteam.factions; +package com.bukkit.mcteam.factions.listeners; import java.util.*; @@ -10,6 +10,8 @@ import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerMoveEvent; +import com.bukkit.mcteam.factions.Commands; +import com.bukkit.mcteam.factions.Factions; import com.bukkit.mcteam.factions.entities.*; import com.bukkit.mcteam.factions.util.*; diff --git a/src/com/bukkit/mcteam/factions/struct/Relation.java b/src/com/bukkit/mcteam/factions/struct/Relation.java index ed7fc53b..c1a4404d 100644 --- a/src/com/bukkit/mcteam/factions/struct/Relation.java +++ b/src/com/bukkit/mcteam/factions/struct/Relation.java @@ -9,7 +9,6 @@ public enum Relation { ALLY(2, "ally"), NEUTRAL(1, "neutral"), ENEMY(0, "enemy"); - //UNKNOWN(-1, "unknown"); public final int value; public final String nicename; @@ -27,22 +26,4 @@ public enum Relation { public ChatColor getColor() { return Conf.relationColor(this); } - - /*public String getChartDot() { - return Conf.chartDot(this); - } - - public static Relation from(String str) { - if (str.equalsIgnoreCase("member")) { - return Relation.MEMBER; - } else if (str.equalsIgnoreCase("ally")) { - return Relation.ALLY; - } else if (str.equalsIgnoreCase("neutral")) { - return Relation.NEUTRAL; - } else if (str.equalsIgnoreCase("enemy")) { - return Relation.ENEMY; - } - - return Relation.UNKNOWN; - }*/ }