Skip to content

Commit

Permalink
Merge pull request #1521 from Dans-Plugins/player-service-refactoring
Browse files Browse the repository at this point in the history
PlayerService Refactoring
  • Loading branch information
dmccoystephenson authored Sep 24, 2022
2 parents bf45050 + b4fed74 commit 7ee929b
Show file tree
Hide file tree
Showing 59 changed files with 357 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public void execute(Player player, String[] args, String key) {

// check if they have provided any strings beyond "addlaw"
if (args.length == 0) {
playerService.sendMessageType(player, translate("&c" + getText("UsageAddLaw")), "UsageAddLaw", false);
playerService.sendMessage(player, translate("&c" + getText("UsageAddLaw")), "UsageAddLaw", false);
return;
}

// add the law and send a success message.
faction.addLaw(String.join(" ", args));
playerService.sendMessageType(player, "&a" + getText("LawAdded"), Objects.requireNonNull(messageService.getLanguage().getString("LawAdded"))
playerService.sendMessage(player, "&a" + getText("LawAdded"), Objects.requireNonNull(messageService.getLanguage().getString("LawAdded"))
.replace("#law#", String.join(" ", args)), true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void execute(Player player, String[] args, String key) {
}

if (args.length == 0) {
playerService.sendMessageType(player, "&c" + getText("UsageAlly"), "UsageAlly", false);
playerService.sendMessage(player, "&c" + getText("UsageAlly"), "UsageAlly", false);
return;
}

Expand All @@ -57,30 +57,30 @@ public void execute(Player player, String[] args, String key) {

// the faction needs to exist to ally
if (otherFaction == null) {
playerService.sendMessageType(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound"))
playerService.sendMessage(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound"))
.replace("#faction#", String.join(" ", args)), true);
return;
}

// the faction can't be itself
if (otherFaction == faction) {
playerService.sendMessageType(player, "&c" + getText("CannotAllyWithSelf"), "CannotAllyWithSelf", false);
playerService.sendMessage(player, "&c" + getText("CannotAllyWithSelf"), "CannotAllyWithSelf", false);
return;
}

// no need to allow them to ally if they're already allies
if (faction.isAlly(otherFaction.getName())) {
playerService.sendMessageType(player, "&c" + getText("FactionAlreadyAlly"), "FactionAlreadyAlly", false);
playerService.sendMessage(player, "&c" + getText("FactionAlreadyAlly"), "FactionAlreadyAlly", false);
return;
}

if (faction.isEnemy(otherFaction.getName())) {
playerService.sendMessageType(player, "&cThat faction is currently at war with your faction.", "FactionIsEnemy", false);
playerService.sendMessage(player, "&cThat faction is currently at war with your faction.", "FactionIsEnemy", false);
return;
}

if (faction.isRequestedAlly(otherFaction.getName())) {
playerService.sendMessageType(player, "&c" + getText("AlertAlreadyRequestedAlliance"), "AlertAlreadyRequestedAlliance", false);
playerService.sendMessage(player, "&c" + getText("AlertAlreadyRequestedAlliance"), "AlertAlreadyRequestedAlliance", false);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void execute(Player player, String[] args, String key) {
}

faction.toggleAutoClaim();
playerService.sendMessageType(player, "&b" + getText("AutoclaimToggled"), "AutoclaimToggled", false);
playerService.sendMessage(player, "&b" + getText("AutoclaimToggled"), "AutoclaimToggled", false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ public void execute(Player player, String[] args, String key) {
}

if (args.length == 0) {
playerService.sendMessageType(player, "&c" + getText("UsageBreakAlliance"), "UsageBreakAlliance", false);
playerService.sendMessage(player, "&c" + getText("UsageBreakAlliance"), "UsageBreakAlliance", false);
return;
}

final Faction otherFaction = getFaction(String.join(" ", args));
if (otherFaction == null) {
playerService.sendMessageType(player, "&c" + getText("FactionNotFound"),
playerService.sendMessage(player, "&c" + getText("FactionNotFound"),
Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound"))
.replace("#faction#", String.join(" ", args)), true);
return;
}

if (otherFaction == faction) {
playerService.sendMessageType(player, "&c" + getText("CannotBreakAllianceWithSelf"), "CannotBreakAllianceWithSelf", false);
playerService.sendMessage(player, "&c" + getText("CannotBreakAllianceWithSelf"), "CannotBreakAllianceWithSelf", false);
return;
}

if (!faction.isAlly(otherFaction.getName())) {
playerService.sendMessageType(player, "&c" + getText("AlertNotAllied", otherFaction.getName()),
playerService.sendMessage(player, "&c" + getText("AlertNotAllied", otherFaction.getName()),
Objects.requireNonNull(messageService.getLanguage().getString("AlertNotAllied"))
.replace("#faction#", otherFaction.getName()), true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void execute(Player player, String[] args, String key) {
} else {
ephemeralData.getAdminsBypassingProtections().add(player.getUniqueId());
}
playerService.sendMessageType(player, "&a" + getText(path), path, false);
playerService.sendMessage(player, "&a" + getText(path), path, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void execute(Player player, String[] args, String key) {
} else {
ephemeralData.getPlayersInFactionChat().add(player.getUniqueId());
}
playerService.sendMessageType(player, "&c" + getText(path), path, false);
playerService.sendMessage(player, "&c" + getText(path), path, false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public void execute(Player player, String[] args, String key) {

if (cancel && contains) {
ephemeralData.getPlayersCheckingAccess().remove(player.getUniqueId());
playerService.sendMessageType(player, "&c" + getText("Cancelled"), "Cancelled", false);
playerService.sendMessage(player, "&c" + getText("Cancelled"), "Cancelled", false);
} else {
if (contains) {
playerService.sendMessageType(player, "&c" + getText("AlreadyEnteredCheckAccess"), "AlreadyEnteredCheckAccess", false);
playerService.sendMessage(player, "&c" + getText("AlreadyEnteredCheckAccess"), "AlreadyEnteredCheckAccess", false);
} else {
ephemeralData.getPlayersCheckingAccess().add(player.getUniqueId());
playerService.sendMessageType(player, "&a" + getText("RightClickCheckAccess"), "RightClickCheckAccess", false);
playerService.sendMessage(player, "&a" + getText("RightClickCheckAccess"), "RightClickCheckAccess", false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void execute(Player player, String[] args, String key) {
final String result = chunkDataAccessor.checkOwnershipAtPlayerLocation(player);

if (result.equals("unclaimed")) {
playerService.sendMessageType(player, "&a" + getText("LandIsUnclaimed"), "LandIsUnclaimed", false);
playerService.sendMessage(player, "&a" + getText("LandIsUnclaimed"), "LandIsUnclaimed", false);
} else {
playerService.sendMessageType(player, "&c" + getText("LandClaimedBy"), Objects.requireNonNull(messageService.getLanguage().getString("LandClaimedBy"))
playerService.sendMessage(player, "&c" + getText("LandClaimedBy"), Objects.requireNonNull(messageService.getLanguage().getString("LandClaimedBy"))
.replace("#player#", result), true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void execute(Player player, String[] args, String key) {
if ((boolean) faction.getFlags().getFlag("mustBeOfficerToManageLand")) {
// officer or owner rank required
if (!faction.isOfficer(player.getUniqueId()) && !faction.isOwner(player.getUniqueId())) {
playerService.sendMessageType(player, "&a" + getText("AlertMustBeOfficerOrOwnerToClaimLand"), "AlertMustBeOfficerOrOwnerToClaimLand", false);
playerService.sendMessage(player, "&a" + getText("AlertMustBeOfficerOrOwnerToClaimLand"), "AlertMustBeOfficerOrOwnerToClaimLand", false);
return;
}
}
Expand All @@ -47,7 +47,7 @@ public void execute(Player player, String[] args, String key) {
int depth = getIntSafe(args[0], -1);

if (depth <= 0) {
playerService.sendMessageType(player, "&a" + getText("UsageClaimRadius"), "UsageClaimRadius", false);
playerService.sendMessage(player, "&a" + getText("UsageClaimRadius"), "UsageClaimRadius", false);
} else {
chunkDataAccessor.radiusClaimAtLocation(depth, player, player.getLocation(), faction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public void execute(Player player, String[] args, String key) {

this.faction = getPlayerFaction(player);
if (this.faction != null) {
playerService.sendMessageType(player, "&c" + getText("AlreadyInFaction"),
playerService.sendMessage(player, "&c" + getText("AlreadyInFaction"),
"AlreadyInFaction", false);
return;
}

if (args.length == 0) {
playerService.sendMessageType(player, "&c" + getText("UsageCreate"),
playerService.sendMessage(player, "&c" + getText("UsageCreate"),
"UsageCreate", false);
return;
}
Expand All @@ -70,14 +70,14 @@ public void execute(Player player, String[] args, String key) {
final FileConfiguration config = configService.getConfig();

if (factionName.length() > config.getInt("factionMaxNameLength")) {
playerService.sendMessageType(player, "&c" + getText("FactionNameTooLong"),
playerService.sendMessage(player, "&c" + getText("FactionNameTooLong"),
Objects.requireNonNull(messageService.getLanguage().getString("FactionNameTooLong"))
.replace("#name#", factionName), true);
return;
}

if (persistentData.getFaction(factionName) != null) {
playerService.sendMessageType(player, "&c" + getText("FactionAlreadyExists"),
playerService.sendMessage(player, "&c" + getText("FactionAlreadyExists"),
Objects.requireNonNull(messageService.getLanguage().getString("FactionAlreadyExists"))
.replace("#name#", factionName), true);
return;
Expand All @@ -91,7 +91,7 @@ public void execute(Player player, String[] args, String key) {
Bukkit.getPluginManager().callEvent(createEvent);
if (!createEvent.isCancelled()) {
persistentData.addFaction(this.faction);
playerService.sendMessageType(player, "&a" + getText("FactionCreated"),
playerService.sendMessage(player, "&a" + getText("FactionCreated"),
Objects.requireNonNull(messageService.getLanguage().getString("FactionCreated"))
.replace("#name#", factionName), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public void execute(Player player, String[] args, String key) {
}

if (!(this.faction.hasLiege()) || this.faction.getLiege() == null) {
playerService.sendMessageType(player, "&c" + getText("NotAVassalOfAFaction"), "NotAVassalOfAFaction", false);
playerService.sendMessage(player, "&c" + getText("NotAVassalOfAFaction"), "NotAVassalOfAFaction", false);
return;
}

final Faction liege = getFaction(this.faction.getLiege());
if (liege == null) {
playerService.sendMessageType(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound")).replace("#faction#", String.join(" ", args)), true);
playerService.sendMessage(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound")).replace("#faction#", String.join(" ", args)), true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void execute(Player player, String[] args, String key) {
}

if (args.length == 0) {
playerService.sendMessageType(player, "&c" + "Usage: /mf declarewar \"faction\"",
playerService.sendMessage(player, "&c" + "Usage: /mf declarewar \"faction\"",
"UsageDeclareWar", false);
return;
}
Expand All @@ -60,7 +60,7 @@ public void execute(Player player, String[] args, String key) {
List<String> doubleQuoteArgs = argumentParser.getArgumentsInsideDoubleQuotes(args);

if (doubleQuoteArgs.size() == 0) {
playerService.sendMessageType(player, "&c" + "Usage: /mf declarewar \"faction\" (quotation marks are required)",
playerService.sendMessage(player, "&c" + "Usage: /mf declarewar \"faction\" (quotation marks are required)",
"UsageDeclareWar", false);
return;
}
Expand All @@ -69,27 +69,27 @@ public void execute(Player player, String[] args, String key) {

final Faction opponent = getFaction(factionName);
if (opponent == null) {
playerService.sendMessageType(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound"))
playerService.sendMessage(player, "&c" + getText("FactionNotFound"), Objects.requireNonNull(messageService.getLanguage().getString("FactionNotFound"))
.replace("#faction#", String.join(" ", args)), true);
return;
}

if (opponent == faction) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnYourself")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnYourself")
, "CannotDeclareWarOnYourself", false);
return;
}

if (faction.isEnemy(opponent.getName())) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnYourself")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnYourself")
, Objects.requireNonNull(messageService.getLanguage().getString("AlertAlreadyAtWarWith")).replace("#faction#", opponent.getName()), true);

return;
}

if (faction.hasLiege() && opponent.hasLiege()) {
if (faction.isVassal(opponent.getName())) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnVassal")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnVassal")
, "CannotDeclareWarOnVassal", false);
return;
}
Expand All @@ -98,33 +98,33 @@ public void execute(Player player, String[] args, String key) {
final Faction enemyLiege = getFaction(opponent.getLiege());
if (enemyLiege.calculateCumulativePowerLevelWithoutVassalContribution() <
enemyLiege.getMaximumCumulativePowerLevel() / 2) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarIfLiegeNotWeakened")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarIfLiegeNotWeakened")
, "CannotDeclareWarIfLiegeNotWeakened", false);
}
}
}

if (faction.isLiege(opponent.getName())) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnLiege")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnLiege")
, "CannotDeclareWarOnLiege", false);
return;
}

if (faction.isAlly(opponent.getName())) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnAlly")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnAlly")
, "CannotDeclareWarOnAlly", false);
return;
}

if (configService.getBoolean("allowNeutrality") && ((boolean) opponent.getFlags().getFlag("neutral"))) {
playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarOnNeutralFaction")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarOnNeutralFaction")
, "CannotDeclareWarOnNeutralFaction", false);
return;
}

if (configService.getBoolean("allowNeutrality") && ((boolean) faction.getFlags().getFlag("neutral"))) {

playerService.sendMessageType(player, "&c" + getText("CannotDeclareWarIfNeutralFaction")
playerService.sendMessage(player, "&c" + getText("CannotDeclareWarIfNeutralFaction")
, "CannotDeclareWarIfNeutralFaction", false);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute(Player player, String[] args, String key) {
}

if (args.length == 0) {
playerService.sendMessageType(player, "&c" + getText("UsageDemote")
playerService.sendMessage(player, "&c" + getText("UsageDemote")
, "UsageDemote", false);
return;
}
Expand All @@ -59,31 +59,31 @@ public void execute(Player player, String[] args, String key) {
}

if (playerToBeDemoted == null) {
playerService.sendMessageType(player, "&c" + getText("PlayerByNameNotFound")
playerService.sendMessage(player, "&c" + getText("PlayerByNameNotFound")
, Objects.requireNonNull(messageService.getLanguage().getString("PlayerByNameNotFound"))
.replace("#name#", args[0]), true);
return;
}

if (playerToBeDemoted.getUniqueId() == player.getUniqueId()) {
playerService.sendMessageType(player, "&c" + getText("CannotDemoteSelf")
playerService.sendMessage(player, "&c" + getText("CannotDemoteSelf")
, "CannotDemoteSelf", false);
return;
}

if (!this.faction.isOfficer(playerToBeDemoted.getUniqueId())) {
playerService.sendMessageType(player, "&c" + getText("PlayerIsNotOfficerOfFaction")
playerService.sendMessage(player, "&c" + getText("PlayerIsNotOfficerOfFaction")
, "PlayerIsNotOfficerOfFaction", false);
return;
}

faction.removeOfficer(playerToBeDemoted.getUniqueId());

if (playerToBeDemoted.isOnline()) {
playerService.sendMessageType(player, "&c" + getText("AlertDemotion")
playerService.sendMessage(player, "&c" + getText("AlertDemotion")
, "AlertDemotion", false);
}
playerService.sendMessageType(player, "&c" + getText("PlayerDemoted")
playerService.sendMessage(player, "&c" + getText("PlayerDemoted")
, Objects.requireNonNull(messageService.getLanguage().getString("PlayerDemoted"))
.replace("#name#", playerToBeDemoted.getName()), true);
}
Expand Down
Loading

0 comments on commit 7ee929b

Please sign in to comment.