Skip to content

Commit

Permalink
Added config.yml and interest features
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguycy committed Jan 17, 2024
1 parent 7c415f5 commit 4382b12
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 3 deletions.
1 change: 1 addition & 0 deletions current.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.4
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.thatguycy</groupId>
<artifactId>WorldDynamicsEngine</artifactId>
<name>WorldDynamicsEngine</name>
<version>0.1.3</version>
<version>0.1.4</version>
<description>WorldDynamics Engine is a Minecraft plugin that adds dynamic policies to your world!</description>
<url>https://github.com/thatguycy/WorldDynamics-Engine</url>
<build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.thatguycy</groupId>
<artifactId>WorldDynamicsEngine</artifactId>
<version>0.1.3</version>
<version>0.1.4</version>
<packaging>jar</packaging>

<name>WorldDynamicsEngine</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class OrganizationProperties {
private Set<String> members; // Player names or Nation names
private OrganizationType type;
private double balance;
private OrganizationAttribute attribute;


public enum OrganizationType {
BUSINESS,
Expand All @@ -18,12 +20,48 @@ public enum OrganizationType {
GOVERNMENTAL
}

public enum OrganizationAttribute {
NONE,
BANK,
PASSPORT_OFFICE,
EMBASSY,
TRADE_CENTER,
CULTURAL_INSTITUTE,
MILITARY_BASE,
RESEARCH_LAB,
EDUCATIONAL_INSTITUTE,
MEDICAL_CENTER,
MARKETPLACE,
TRANSPORT_HUB,
LEGAL_COURT,
ENVIRONMENTAL_AGENCY,
HOUSING_COMPLEX,
AGRICULTURAL_FACILITY,
ENERGY_PLANT,
NEWS_AGENCY,
ENTERTAINMENT_VENUE,
TOURIST_ATTRACTION
// ... other attributes as needed
}



public OrganizationProperties(String name, String leader, OrganizationType type) {
this.name = name;
this.leader = leader;
this.type = type;
this.members = new HashSet<>();
this.balance = 0.0;
this.attribute = OrganizationAttribute.NONE; // Set the default attribute to NONE
}


public void setAttribute(OrganizationAttribute attribute) {
this.attribute = attribute;
}

public OrganizationAttribute getAttribute() {
return attribute;
}

// Getters and Setters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.thatguycy.worlddynamicsengine;
import com.palmergames.bukkit.towny.object.Town;
import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import com.palmergames.bukkit.towny.TownyUniverse;
Expand Down Expand Up @@ -74,6 +75,8 @@ private boolean handleOrgCommand(Player player, String[] args) {
return true;
}
return handleCreateOrganization(player, args);
case "setattr":
return handleSetAttribute(player, args);
case "info":
return handleOrgInfo(player, args);
case "deposit":
Expand Down Expand Up @@ -117,6 +120,7 @@ private boolean displayHelp(CommandSender sender) {
sender.sendMessage(ChatColor.GOLD + "/wde" + ChatColor.YELLOW + " org addmember <orgname> <user> -" + ChatColor.WHITE + " Add a member to a GOVERNMENTAL organization (OrgLeader only).");
sender.sendMessage(ChatColor.GOLD + "/wde" + ChatColor.YELLOW + " org kickmember <orgname> <user> -" + ChatColor.WHITE + " Remove a member from an organization (OrgLeader only).");
sender.sendMessage(ChatColor.GOLD + "/wde" + ChatColor.YELLOW + " org info <orgname> -" + ChatColor.WHITE + "Display information about an organization.");
sender.sendMessage(ChatColor.GOLD + "/wde" + ChatColor.YELLOW + " org setattr <orgname> <attribute> -" + ChatColor.WHITE + "Set an organization's attribute.");

return true;
}
Expand Down Expand Up @@ -661,6 +665,8 @@ public void displayOrgInfo(CommandSender sender, String orgName) {
sender.sendMessage(ChatColor.YELLOW + "Members: " + ChatColor.WHITE + (members.isEmpty() ? "None" : members));
String balance = String.format("$%.2f", orgProps.getBalance());
sender.sendMessage(ChatColor.YELLOW + "Balance: " + ChatColor.WHITE + balance);
String orgAttr = orgProps.getType() != null ? orgProps.getAttribute().name() : "None";
sender.sendMessage(ChatColor.YELLOW + "Organization Attribute: " + ChatColor.WHITE + orgAttr);

} else {
// Organization does not exist
Expand Down Expand Up @@ -886,6 +892,82 @@ private boolean handleOrgKickMember(Player player, String[] args) {
player.sendMessage(ChatColor.GREEN + "User '" + userName + "' has been removed from the organization: " + orgName);
return true;
}
private boolean handleSetAttribute(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "Only players can use this command.");
return true;
}

Player player = (Player) sender;

if (args.length < 4) {
sender.sendMessage(ChatColor.RED + "Usage: /wde org setattr <orgName> <attribute>");
return true;
}

String orgName = args[2];
String attributeName = args[3].toUpperCase();

// Retrieve the organization
OrganizationProperties org = organizationManager.getOrganization(orgName);
if (org == null) {
sender.sendMessage(ChatColor.RED + "Organization '" + orgName + "' not found.");
return true;
}

// Get the nation this organization belongs to
Nation orgNation = getNationForOrganization(org); // Implement this method
if (orgNation == null) {
sender.sendMessage(ChatColor.RED + "The organization '" + orgName + "' does not belong to any nation.");
return true;
}

// Check if the sender is the leader of the nation
if (!isNationLeader(player, orgNation)) {
sender.sendMessage(ChatColor.RED + "You must be the leader of the nation to set attributes for its organizations.");
return true;
}

// Check if the attribute is valid and set it
try {
OrganizationProperties.OrganizationAttribute attribute = OrganizationProperties.OrganizationAttribute.valueOf(attributeName);
org.setAttribute(attribute);
organizationManager.saveOrganizations(); // Save the organization data
sender.sendMessage(ChatColor.GREEN + "Attribute '" + attribute + "' set successfully for organization '" + orgName + "'.");
} catch (IllegalArgumentException e) {
sender.sendMessage(ChatColor.RED + "Invalid attribute. Valid attributes are: NONE, BANK, PASSPORT_OFFICE, ...");
}

return true;
}

private Nation getNationForOrganization(OrganizationProperties org) {
try {
// Get the leader of the organization
String leaderName = org.getLeader();

// Use Towny API to get the Resident object for the leader
Resident leaderResident = TownyUniverse.getInstance().getResident(leaderName);
if (leaderResident == null || !leaderResident.hasTown()) {
return null; // Leader is not part of any town
}

// Get the town of the resident
Town town = leaderResident.getTown();

// Check if the town is part of a nation
if (!town.hasNation()) {
return null; // The town is not part of a nation
}

// Return the nation
return town.getNation();

} catch (NotRegisteredException e) {
// This exception is thrown if the resident doesn't exist or isn't part of a town/nation
return null;
}
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case "army":
return getListOfStringsMatchingLastWord(args, "leave", "setleader", "addmember", "kickmember");
case "org":
return getListOfStringsMatchingLastWord(args, "create", "deposit", "withdraw", "join", "leave", "addmember", "kickmember", "info");
return getListOfStringsMatchingLastWord(args, "create", "deposit", "withdraw", "join", "leave", "addmember", "kickmember", "info", "setattr");
}
} else if (args.length == 3) {
if (args[0].equalsIgnoreCase("government") && args[1].equalsIgnoreCase("settype")) {
Expand All @@ -50,6 +50,13 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
case "kickmember":
case "info":
return getListOfOrgNames(); // Assuming this method returns a list of existing organization names
case "setattr":
if (args.length == 3) { // When typing the organization name
return getListOfOrgNames();
} else if (args.length == 4) { // When typing the attribute
return getListOfOrgAttributes(args);
}
break;
}
}
}
Expand Down Expand Up @@ -89,6 +96,31 @@ private List<String> getListOfOrgTypes() {
return Arrays.asList("BUSINESS", "GOVERNMENTAL", "INTERNATIONAL");
}

private List<String> getListOfOrgAttributes() {
return Arrays.asList(
"NONE",
"BANK",
"PASSPORT_OFFICE",
"EMBASSY",
"TRADE_CENTER",
"CULTURAL_INSTITUTE",
"MILITARY_BASE",
"RESEARCH_LAB",
"EDUCATIONAL_INSTITUTE",
"MEDICAL_CENTER",
"MARKETPLACE",
"TRANSPORT_HUB",
"LEGAL_COURT",
"ENVIRONMENTAL_AGENCY",
"HOUSING_COMPLEX",
"AGRICULTURAL_FACILITY",
"ENERGY_PLANT",
"NEWS_AGENCY",
"ENTERTAINMENT_VENUE",
"TOURIST_ATTRACTION"
);
}

private List<String> getListOfOrgNames() {
return new ArrayList<>(organizationManager.getOrganizations().keySet());
}
Expand Down

0 comments on commit 4382b12

Please sign in to comment.