Skip to content

Commit

Permalink
QOL interface changes/redundancy removal (#3677)
Browse files Browse the repository at this point in the history
* QOL changes/redundancy removal

- Removed TownyAllySender, and ResidentModes.java because they were only being used in singular classes defeating the purpose of the interface, so they were combined into their respective classes.
- Made PlotGroup conform to TownBlockOwner to introduce more standard implementation.
- New interface Nameable introduced in order for objects that don't extend `TownyObject` to be operated on i.e PlotGroups.

* New Bank interface

* Added Bank interface to generify objects that contain banks.

* Remove and clean up Town/Nation code

* Simplified a lot of Town/Nation code and removed some that didn't do anything.

* Clean up Town, Resident, and TownyObject

* Add push compile github action.

* Fix workflow not fetching repo data.

* Update workflow name

* Last workflow update 😅

* Last workflow update 😅
  • Loading branch information
Siris authored Feb 11, 2020
1 parent e2bff20 commit 7bbb11d
Show file tree
Hide file tree
Showing 28 changed files with 255 additions and 300 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/compile-on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Maven Compile
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Compile with Maven
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "<settings><servers><server><id>github-towny</id><username>TownyAdvanced</username><password>${GITHUB_TOKEN}</password></server>" > ~/.m2/settings.xml
echo "<server><id>github-tne</id><username>TownyAdvanced</username><password>${GITHUB_TOKEN}</password></server></servers></settings>" >> ~/.m2/settings.xml
mvn compile
6 changes: 3 additions & 3 deletions src/com/palmergames/bukkit/towny/ChunkNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -72,7 +72,7 @@ public static void loadFormatStrings() {
Town fromTown = null, toTown = null;
Resident fromResident = null, toResident = null;
TownBlockType fromPlotType = null, toPlotType = null;
PlotObjectGroup fromPlotGroup = null, toPlotGroup = null;
PlotGroup fromPlotGroup = null, toPlotGroup = null;

public ChunkNotification(WorldCoord from, WorldCoord to) {

Expand Down Expand Up @@ -342,7 +342,7 @@ public String getForSaleNotification() {

public String getGroupNotification() {
if (toPlotGroupBlock && (fromPlotGroup != toPlotGroup))
return String.format(groupNotificationFormat, toTownBlock.getPlotObjectGroup().getGroupName());
return String.format(groupNotificationFormat, toTownBlock.getPlotObjectGroup().getName());
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/palmergames/bukkit/towny/TownyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static List<String> getStatus(TownBlock townBlock) {
TownySettings.getLangString("mobspawns") + ((town.hasMobs() || world.isForceTownMobs() || townBlock.getPermissions().mobs) ? TownySettings.getLangString("status_on"): TownySettings.getLangString("status_off")));

if (townBlock.hasPlotObjectGroup())
out.add(String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getGroupName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));
out.add(String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));
out.addAll(getExtraFields(townBlock));
} catch (NotRegisteredException e) {
out.add("Error: " + e.getMessage());
Expand Down
18 changes: 9 additions & 9 deletions src/com/palmergames/bukkit/towny/TownyUniverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Coord;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
Expand Down Expand Up @@ -390,8 +390,8 @@ public boolean hasGroup(String townName, String groupName) {
*
* @return collection of PlotObjectGroup
*/
public Collection<PlotObjectGroup> getGroups() {
List<PlotObjectGroup> groups = new ArrayList<>();
public Collection<PlotGroup> getGroups() {
List<PlotGroup> groups = new ArrayList<>();

for (Town town : towns.values()) {
if (town.hasObjectGroups()) {
Expand All @@ -410,7 +410,7 @@ public Collection<PlotObjectGroup> getGroups() {
* @param groupID UUID of the plot group
* @return PlotGroup if found, null if none found.
*/
public PlotObjectGroup getGroup(String townName, UUID groupID) {
public PlotGroup getGroup(String townName, UUID groupID) {
Town t = null;
try {
t = TownyUniverse.getInstance().getDataSource().getTown(townName);
Expand All @@ -431,7 +431,7 @@ public PlotObjectGroup getGroup(String townName, UUID groupID) {
* @param groupName Plot Group Name
* @return the plot group if found, otherwise null
*/
public PlotObjectGroup getGroup(String townName, String groupName) {
public PlotGroup getGroup(String townName, String groupName) {
Town t = towns.get(townName);

if (t != null) {
Expand All @@ -445,13 +445,13 @@ public HashMap<String, CustomDataField> getRegisteredMetadataMap() {
return getRegisteredMetadata();
}

public PlotObjectGroup newGroup(Town town, String name, UUID id) throws AlreadyRegisteredException {
public PlotGroup newGroup(Town town, String name, UUID id) throws AlreadyRegisteredException {

// Create new plot group.
PlotObjectGroup newGroup = new PlotObjectGroup(id, name, town);
PlotGroup newGroup = new PlotGroup(id, name, town);

// Check if there is a duplicate
if (town.hasObjectGroupName(newGroup.getGroupName())) {
if (town.hasObjectGroupName(newGroup.getName())) {
TownyMessaging.sendErrorMsg("group " + town.getName() + ":" + id + " already exists"); // FIXME Debug message
throw new AlreadyRegisteredException();
}
Expand All @@ -467,7 +467,7 @@ public UUID generatePlotGroupID() {
}


public void removeGroup(PlotObjectGroup group) {
public void removeGroup(PlotGroup group) {
group.getTown().removePlotGroup(group);

}
Expand Down
42 changes: 21 additions & 21 deletions src/com/palmergames/bukkit/towny/command/PlotCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Coord;
import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
Expand Down Expand Up @@ -160,7 +160,7 @@ public boolean parsePlotCommand(Player player, String[] split) throws TownyExcep

if (block.hasPlotObjectGroup()) {
// This block is part of a group, special tasks need to be done.
PlotObjectGroup group = block.getPlotObjectGroup();
PlotGroup group = block.getPlotObjectGroup();

// Add the confirmation for claiming a plot group.
ConfirmationHandler.addConfirmation(resident, ConfirmationType.GROUP_CLAIM_ACTION, new GroupConfirmation(group, player));
Expand Down Expand Up @@ -245,7 +245,7 @@ public boolean parsePlotCommand(Player player, String[] split) throws TownyExcep
townyUniverse.getDataSource().saveTownBlock(tb);
}

player.sendMessage(String.format(TownySettings.getLangString("msg_plot_evict_group"), townBlock.getPlotObjectGroup().getGroupName()));
player.sendMessage(String.format(TownySettings.getLangString("msg_plot_evict_group"), townBlock.getPlotObjectGroup().getName()));
return true;
}

Expand Down Expand Up @@ -880,7 +880,7 @@ public void setPlotForSale(Resident resident, WorldCoord worldCoord, double forS
throw new TownyException(TownySettings.getLangString("msg_err_must_belong_town"));
}

public void setGroupForSale(Resident resident, PlotObjectGroup group, double price) throws TownyException {
public void setGroupForSale(Resident resident, PlotGroup group, double price) throws TownyException {
group.setPrice(price);

if (resident.hasTown()) {
Expand All @@ -894,9 +894,9 @@ public void setGroupForSale(Resident resident, PlotObjectGroup group, double pri
}

if (price != -1) {
TownyMessaging.sendPrefixedTownMessage(resident.getTown(), String.format(TownySettings.getLangString("msg_plot_group_set_for_sale"), group.getGroupName()));
TownyMessaging.sendPrefixedTownMessage(resident.getTown(), String.format(TownySettings.getLangString("msg_plot_group_set_for_sale"), group.getName()));
if (group.getTown() != resident.getTown())
TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_plot_group_set_for_sale"), group.getGroupName()));
TownyMessaging.sendMessage(resident, String.format(TownySettings.getLangString("msg_plot_group_set_for_sale"), group.getName()));
} else {
Player p = TownyAPI.getInstance().getPlayer(resident);
if (p == null) {
Expand Down Expand Up @@ -1003,7 +1003,7 @@ public void plotToggle(Player player, TownBlock townBlock, String[] split) {
* @param plotGroup - PlotObjectGroup object.
* @param split - Current command arguments.
*/
public void plotGroupToggle(Player player, PlotObjectGroup plotGroup, String[] split) {
public void plotGroupToggle(Player player, PlotGroup plotGroup, String[] split) {
TownyUniverse townyUniverse = TownyUniverse.getInstance();

if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
Expand Down Expand Up @@ -1237,18 +1237,18 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
player.sendMessage(ChatTools.formatCommand("/plot group", "notforsale | nfs", "", "Ex: /plot group notforsale"));

if (townBlock.hasPlotObjectGroup())
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getGroupName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));

return true;
}

if (split[0].equalsIgnoreCase("add") || split[0].equalsIgnoreCase("new") || split[0].equalsIgnoreCase("create")) {

// Add the group to the new plot.
PlotObjectGroup newGroup = null;
PlotGroup newGroup = null;

if (townBlock.hasPlotObjectGroup()) {
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_plot_already_belongs_to_a_group"), townBlock.getPlotObjectGroup().getGroupName()));
TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_plot_already_belongs_to_a_group"), townBlock.getPlotObjectGroup().getName()));
return false;
}

Expand All @@ -1257,11 +1257,11 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
UUID plotGroupID = townyUniverse.generatePlotGroupID();
String plotGroupName = split[1];

newGroup = new PlotObjectGroup(plotGroupID, plotGroupName, town);
newGroup = new PlotGroup(plotGroupID, plotGroupName, town);

// Don't add the group to the town data if it's already there.
if (town.hasObjectGroupName(newGroup.getGroupName())) {
newGroup = town.getPlotObjectGroupFromName(newGroup.getGroupName());
if (town.hasObjectGroupName(newGroup.getName())) {
newGroup = town.getPlotObjectGroupFromName(newGroup.getName());
}

townBlock.setPlotObjectGroup(newGroup);
Expand All @@ -1285,15 +1285,15 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
townyUniverse.getDataSource().saveTownBlock(townBlock);
townyUniverse.getDataSource().saveTown(town);

TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_plot_was_put_into_group_x"), townBlock.getX(), townBlock.getZ(), newGroup.getGroupName()));
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_plot_was_put_into_group_x"), townBlock.getX(), townBlock.getZ(), newGroup.getName()));

} else if (split[0].equalsIgnoreCase("remove")) {

if (!townBlock.hasPlotObjectGroup()) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_plot_not_associated_with_a_group"));
return false;
}
String name = townBlock.getPlotObjectGroup().getGroupName();
String name = townBlock.getPlotObjectGroup().getName();
// Remove the plot from the group.
townBlock.getPlotObjectGroup().removeTownBlock(townBlock);

Expand All @@ -1313,14 +1313,14 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
return false;
}

String oldName = townBlock.getPlotObjectGroup().getGroupName();
String oldName = townBlock.getPlotObjectGroup().getName();
// Change name;
TownyUniverse.getInstance().getDataSource().renameGroup(townBlock.getPlotObjectGroup(), newName);
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_plot_renamed_from_x_to_y"), oldName, newName));

} else if (split[0].equalsIgnoreCase("forsale") || split[0].equalsIgnoreCase("fs")) {
// This means the player wants to fs the plot group they are in.
PlotObjectGroup group = townBlock.getPlotObjectGroup();
PlotGroup group = townBlock.getPlotObjectGroup();

if (group == null) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_plot_not_associated_with_a_group"));
Expand All @@ -1340,11 +1340,11 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
TownyUniverse.getInstance().getDataSource().savePlotGroup(group);
TownyUniverse.getInstance().getDataSource().savePlotGroupList();

TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_player_put_group_up_for_sale"), player.getName(), group.getGroupName(), TownyEconomyHandler.getFormattedBalance(group.getPrice())));
TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_player_put_group_up_for_sale"), player.getName(), group.getName(), TownyEconomyHandler.getFormattedBalance(group.getPrice())));

} else if (split[0].equalsIgnoreCase("notforsale") || split[0].equalsIgnoreCase("nfs")) {
// This means the player wants to nfs the plot group they are in.
PlotObjectGroup group = townBlock.getPlotObjectGroup();
PlotGroup group = townBlock.getPlotObjectGroup();

if (group == null) {
TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_plot_not_associated_with_a_group"));
Expand All @@ -1357,7 +1357,7 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
TownyUniverse.getInstance().getDataSource().savePlotGroup(group);
TownyUniverse.getInstance().getDataSource().savePlotGroupList();

TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_player_made_group_not_for_sale"), player.getName(), group.getGroupName()));
TownyMessaging.sendPrefixedTownMessage(town, String.format(TownySettings.getLangString("msg_player_made_group_not_for_sale"), player.getName(), group.getName()));
} else if (split[0].equalsIgnoreCase("toggle")) {

if (townBlock.getPlotObjectGroup() == null) {
Expand Down Expand Up @@ -1442,7 +1442,7 @@ private boolean handlePlotGroupCommand(String[] split, Player player) throws Tow
player.sendMessage(ChatTools.formatCommand("/plot group", "notforsale | nfs", "", "Ex: /plot group notforsale"));

if (townBlock.hasPlotObjectGroup())
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getGroupName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));
TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("status_plot_group_name_and_size"), townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size()));

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.palmergames.bukkit.towny.event.TownBlockSettingsChangedEvent;
import com.palmergames.bukkit.towny.exceptions.TownyException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
Expand Down Expand Up @@ -372,11 +372,11 @@ public static void handleConfirmation(Resident r, ConfirmationType type) throws

/**
* A simple method to get coordinates from plot group plots.
* @param group The {@link PlotObjectGroup} to get the coords from.
* @param group The {@link PlotGroup} to get the coords from.
* @return An {@link ArrayList} of {@link WorldCoord}'s.
* @author Suneet Tipirneni (Siris)
*/
private static ArrayList<WorldCoord> plotGroupBlocksToCoords(PlotObjectGroup group) {
private static ArrayList<WorldCoord> plotGroupBlocksToCoords(PlotGroup group) {
ArrayList<WorldCoord> coords = new ArrayList<>();

for (TownBlock tb : group.getTownBlocks()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package com.palmergames.bukkit.towny.confirmations;

import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.TownBlockOwner;

import org.bukkit.entity.Player;

import java.util.Objects;

public class GroupConfirmation {
private PlotObjectGroup group;
private PlotGroup group;
private Player player;
private String[] args;
private TownBlockOwner owner;

public GroupConfirmation(PlotObjectGroup group, Player player) {
public GroupConfirmation(PlotGroup group, Player player) {
this.group = group;
this.player = player;
}


public PlotObjectGroup getGroup() {
public PlotGroup getGroup() {
return group;
}

Expand Down
12 changes: 6 additions & 6 deletions src/com/palmergames/bukkit/towny/db/TownyDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.PlotObjectGroup;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownBlock;
Expand Down Expand Up @@ -124,7 +124,7 @@ public boolean saveQueues() {

abstract public boolean saveTown(Town town);

abstract public boolean savePlotGroup(PlotObjectGroup group);
abstract public boolean savePlotGroup(PlotGroup group);

abstract public boolean saveNation(Nation nation);

Expand Down Expand Up @@ -154,7 +154,7 @@ public boolean saveQueues() {

abstract public void deleteFile(String file);

abstract public void deletePlotGroup(PlotObjectGroup group);
abstract public void deletePlotGroup(PlotGroup group);

public boolean cleanup() {

Expand Down Expand Up @@ -233,7 +233,7 @@ public boolean saveResidents() {

public boolean savePlotGroups() {
TownyMessaging.sendDebugMsg("Saving PlotGroups");
for (PlotObjectGroup plotGroup : getAllPlotGroups())
for (PlotGroup plotGroup : getAllPlotGroups())
savePlotGroup(plotGroup);
return true;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ public boolean saveWorlds() {

abstract public List<Resident> getResidents();

abstract public List<PlotObjectGroup> getAllPlotGroups();
abstract public List<PlotGroup> getAllPlotGroups();

abstract public List<Resident> getResidents(String[] names);

Expand Down Expand Up @@ -343,5 +343,5 @@ public boolean saveWorlds() {

abstract public void renamePlayer(Resident resident, String newName) throws AlreadyRegisteredException, NotRegisteredException;

abstract public void renameGroup(PlotObjectGroup group, String newName) throws AlreadyRegisteredException;
abstract public void renameGroup(PlotGroup group, String newName) throws AlreadyRegisteredException;
}
Loading

0 comments on commit 7bbb11d

Please sign in to comment.