-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from dmccoystephenson/fief-flags
Fief Flags
- Loading branch information
Showing
9 changed files
with
267 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/dansplugins/fiefs/commands/FlagsCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package dansplugins.fiefs.commands; | ||
|
||
import dansplugins.factionsystem.externalapi.MF_Faction; | ||
import dansplugins.fiefs.MedievalFactionsIntegrator; | ||
import dansplugins.fiefs.data.PersistentData; | ||
import dansplugins.fiefs.objects.Fief; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
|
||
public class FlagsCommand { | ||
|
||
public boolean execute(CommandSender sender, String[] args) { | ||
|
||
if (!(sender instanceof Player)) { | ||
sender.sendMessage("Only players can use this command."); | ||
return false; | ||
} | ||
|
||
Player player = (Player) sender; | ||
|
||
MF_Faction faction = MedievalFactionsIntegrator.getInstance().getAPI().getFaction(player); | ||
if (faction == null) { | ||
player.sendMessage(ChatColor.RED + "You must be in a faction to use this command."); | ||
return false; | ||
} | ||
|
||
Fief playersFief = PersistentData.getInstance().getFief(player); | ||
if (playersFief == null) { | ||
player.sendMessage(ChatColor.RED + "You must be in a fief to use this command."); | ||
return false; | ||
} | ||
|
||
if (!playersFief.getOwnerUUID().equals(player.getUniqueId())) { | ||
player.sendMessage(ChatColor.RED + "You must be the owner of your fief to kick members."); | ||
return false; | ||
} | ||
|
||
if (args.length == 0) { | ||
player.sendMessage(ChatColor.RED + "Valid sub-commands: show, set"); | ||
return false; | ||
} | ||
|
||
if (args[0].equalsIgnoreCase("show")) { | ||
playersFief.getFlags().sendFlagList(player); | ||
} | ||
else if (args[0].equalsIgnoreCase("set")) { | ||
if (args.length < 3) { | ||
player.sendMessage(ChatColor.RED + "Usage: /fi flags set (flag) (value)"); | ||
return false; | ||
} | ||
else { | ||
playersFief.getFlags().setFlag(args[1], args[2], player); | ||
} | ||
} | ||
else { | ||
player.sendMessage(ChatColor.RED + "Valid sub-commands: show, set"); | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package dansplugins.fiefs.objects; | ||
|
||
import dansplugins.fiefs.Fiefs; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
public class FiefFlags { | ||
|
||
/* | ||
In order to add a new fief flag to this class, the following methods need to be altered: | ||
- initializeFlagNames() | ||
- initializeFlagValues() | ||
- loadMissingFlagsIfNecessary() | ||
*/ | ||
|
||
private ArrayList<String> flagNames = new ArrayList<>(); | ||
private HashMap<String, Integer> integerValues = new HashMap<>(); | ||
private HashMap<String, Boolean> booleanValues = new HashMap<>(); | ||
private HashMap<String, Double> doubleValues = new HashMap<>(); | ||
private HashMap<String, String> stringValues = new HashMap<>(); | ||
|
||
public FiefFlags() { | ||
initializeFlagNames(); | ||
} | ||
|
||
private void initializeFlagNames() { // this is called internally | ||
flagNames.add("claimedLandProtected"); | ||
} | ||
|
||
public void initializeFlagValues() { | ||
// this is called externally in Fief.java when a fief is created in-game | ||
booleanValues.put("claimedLandProtected", true); | ||
} | ||
|
||
public void loadMissingFlagsIfNecessary() { | ||
// this is called externally in Fief.java when a fief is loaded from save files | ||
if (!booleanValues.containsKey("claimedLandProtected")) { | ||
booleanValues.put("claimedLandProtected", true); | ||
} | ||
} | ||
|
||
public void sendFlagList(Player player) { | ||
player.sendMessage(ChatColor.AQUA + "" + getFlagsSeparatedByCommas()); | ||
} | ||
|
||
|
||
public void setFlag(String flag, String value, Player player) { | ||
|
||
if (isFlag(flag)) { | ||
if (integerValues.containsKey(flag)) { | ||
integerValues.replace(flag, Integer.parseInt(value)); | ||
player.sendMessage(ChatColor.GREEN + "Integer set."); | ||
} | ||
else if (booleanValues.containsKey(flag)) { | ||
booleanValues.replace(flag, Boolean.parseBoolean(value)); | ||
player.sendMessage(ChatColor.GREEN + "Boolean set."); | ||
} | ||
else if (doubleValues.containsKey(flag)) { | ||
doubleValues.replace(flag, Double.parseDouble(value)); | ||
player.sendMessage(ChatColor.GREEN + "Double set."); | ||
} | ||
else if (stringValues.containsKey(flag)) { | ||
stringValues.replace(flag, value); | ||
player.sendMessage(ChatColor.GREEN + "String set."); | ||
} | ||
} | ||
else { | ||
player.sendMessage(ChatColor.RED + "That fief flag wasn't found."); | ||
} | ||
} | ||
|
||
public Object getFlag(String flag) { | ||
if (!isFlag(flag)) { | ||
if (Fiefs.getInstance().isDebugEnabled()) { System.out.println(String.format("[DEBUG] Flag '%s' was not found!", flag)); } | ||
return false; | ||
} | ||
|
||
if (integerValues.containsKey(flag)) { | ||
if (Fiefs.getInstance().isDebugEnabled()) { System.out.println(String.format("[DEBUG] Flag '%s' was found! Value: '%s'", flag, integerValues.get(flag))); } | ||
return integerValues.get(flag); | ||
} | ||
else if (booleanValues.containsKey(flag)) { | ||
if (Fiefs.getInstance().isDebugEnabled()) { System.out.println(String.format("[DEBUG] Flag '%s' was found! Value: '%s'", flag, booleanValues.get(flag))); } | ||
return booleanValues.get(flag); | ||
} | ||
else if (doubleValues.containsKey(flag)) { | ||
if (Fiefs.getInstance().isDebugEnabled()) { System.out.println(String.format("[DEBUG] Flag '%s' was found! Value: '%s'", flag, doubleValues.get(flag))); } | ||
return doubleValues.get(flag); | ||
} | ||
else if (stringValues.containsKey(flag)) { | ||
if (Fiefs.getInstance().isDebugEnabled()) { System.out.println(String.format("[DEBUG] Flag '%s' was found! Value: '%s'", flag, stringValues.get(flag))); } | ||
return stringValues.get(flag); | ||
} | ||
return null; | ||
} | ||
|
||
public HashMap<String, Integer> getIntegerValues() { | ||
return integerValues; | ||
} | ||
|
||
public void setIntegerValues(HashMap<String, Integer> values) { | ||
integerValues = values; | ||
} | ||
|
||
public HashMap<String, Boolean> getBooleanValues() { | ||
return booleanValues; | ||
} | ||
|
||
public void setBooleanValues(HashMap<String, Boolean> values) { | ||
booleanValues = values; | ||
} | ||
|
||
public HashMap<String, Double> getDoubleValues() { | ||
return doubleValues; | ||
} | ||
|
||
public void setDoubleValues(HashMap<String, Double> values) { | ||
doubleValues = values; | ||
} | ||
|
||
public HashMap<String, String> getStringValues() { | ||
return stringValues; | ||
} | ||
|
||
public void setStringValues(HashMap<String, String> values) { | ||
stringValues = values; | ||
} | ||
|
||
private boolean isFlag(String flag) { | ||
// this method will likely need to be used to sanitize user input | ||
return flagNames.contains(flag); | ||
} | ||
|
||
public int getNumFlags() { | ||
return booleanValues.size(); | ||
} | ||
|
||
private String getFlagsSeparatedByCommas() { | ||
String toReturn = ""; | ||
for (String flagName : flagNames) { | ||
|
||
if (!toReturn.equals("")) { | ||
toReturn += ", "; | ||
} | ||
if (integerValues.containsKey(flagName)) { | ||
toReturn += String.format("%s: %s", flagName, integerValues.get(flagName)); | ||
} | ||
else if (booleanValues.containsKey(flagName)) { | ||
toReturn += String.format("%s: %s", flagName, booleanValues.get(flagName)); | ||
} | ||
else if (doubleValues.containsKey(flagName)) { | ||
toReturn += String.format("%s: %s", flagName, doubleValues.get(flagName)); | ||
} | ||
else if (stringValues.containsKey(flagName)) { | ||
toReturn += String.format("%s: %s", flagName, stringValues.get(flagName)); | ||
} | ||
} | ||
return toReturn; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: Fiefs | ||
version: 0.6 | ||
version: 0.7 | ||
main: dansplugins.fiefs.Fiefs | ||
api-version: 1.13 | ||
author: DanTheTechMan | ||
|