Skip to content
Permalink
Browse files

QOL interface changes/redundancy removal (#3677)

* 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
suneettipirneni committed Feb 11, 2020
1 parent e2bff20 commit 7bbb11d7cb204f19116f21336b3eb35133907c6f
Showing with 255 additions and 300 deletions.
  1. +18 −0 .github/workflows/compile-on-push.yml
  2. +3 −3 src/com/palmergames/bukkit/towny/ChunkNotification.java
  3. +1 −1 src/com/palmergames/bukkit/towny/TownyFormatter.java
  4. +9 −9 src/com/palmergames/bukkit/towny/TownyUniverse.java
  5. +21 −21 src/com/palmergames/bukkit/towny/command/PlotCommand.java
  6. +3 −3 src/com/palmergames/bukkit/towny/confirmations/ConfirmationHandler.java
  7. +4 −4 src/com/palmergames/bukkit/towny/confirmations/GroupConfirmation.java
  8. +6 −6 src/com/palmergames/bukkit/towny/db/TownyDataSource.java
  9. +8 −12 src/com/palmergames/bukkit/towny/db/TownyDatabaseHandler.java
  10. +11 −11 src/com/palmergames/bukkit/towny/db/TownyFlatFileSource.java
  11. +9 −9 src/com/palmergames/bukkit/towny/db/TownySQLSource.java
  12. +3 −3 src/com/palmergames/bukkit/towny/invites/InviteHandler.java
  13. +0 −15 src/com/palmergames/bukkit/towny/invites/TownyAllySender.java
  14. +2 −2 src/com/palmergames/bukkit/towny/invites/TownyInviteSender.java
  15. +19 −0 src/com/palmergames/bukkit/towny/object/Bank.java
  16. +14 −0 src/com/palmergames/bukkit/towny/object/Nameable.java
  17. +13 −24 src/com/palmergames/bukkit/towny/object/Nation.java
  18. +5 −3 src/com/palmergames/bukkit/towny/object/ObjectGroup.java
  19. +1 −1 src/com/palmergames/bukkit/towny/object/ObjectGroupManageable.java
  20. +24 −9 src/com/palmergames/bukkit/towny/object/{PlotObjectGroup.java → PlotGroup.java}
  21. +10 −17 src/com/palmergames/bukkit/towny/object/Resident.java
  22. +0 −23 src/com/palmergames/bukkit/towny/object/ResidentModes.java
  23. +37 −85 src/com/palmergames/bukkit/towny/object/Town.java
  24. +15 −26 src/com/palmergames/bukkit/towny/object/TownBlock.java
  25. +5 −0 src/com/palmergames/bukkit/towny/object/TownyInviter.java
  26. +5 −4 src/com/palmergames/bukkit/towny/object/TownyObject.java
  27. +4 −4 src/com/palmergames/bukkit/towny/tasks/PlotClaim.java
  28. +5 −5 src/com/palmergames/bukkit/towny/utils/AreaSelectionUtil.java
@@ -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
@@ -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;

@@ -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) {

@@ -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;
}

@@ -134,7 +134,7 @@ public static String getTime() {
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());
@@ -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;
@@ -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()) {
@@ -410,7 +410,7 @@ public boolean hasGroup(String townName, String groupName) {
* @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);
@@ -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) {
@@ -445,13 +445,13 @@ public PlotObjectGroup getGroup(String townName, String groupName) {
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();
}
@@ -467,7 +467,7 @@ public UUID generatePlotGroupID() {
}


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

}
@@ -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;
@@ -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));
@@ -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;
}

@@ -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()) {
@@ -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) {
@@ -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("?")) {
@@ -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;
}

@@ -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);
@@ -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);

@@ -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"));
@@ -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"));
@@ -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) {
@@ -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;
}
@@ -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;
@@ -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()) {
@@ -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;
}

@@ -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;
@@ -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);

@@ -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() {

@@ -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;
}
@@ -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);

@@ -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;
}

0 comments on commit 7bbb11d

Please sign in to comment.
You can’t perform that action at this time.