mirror of
https://github.com/NLthijs48/AreaShop.git
synced 2025-02-17 04:11:30 +01:00
Add the '/as delfriend' command and minor changes the addfriend command
This commit is contained in:
parent
a25b5a5752
commit
59627e1b97
12
lang/EN.yml
12
lang/EN.yml
@ -60,6 +60,8 @@ help-stopResell: "&6/as stopresell &7-&r Put your region back into sold mode"
|
||||
help-stopResellAll: "&6/as stopresell &7-&r Put a region back into sold mode"
|
||||
help-addFriend: "&6/as addfriend &7-&r Add a friend to your region"
|
||||
help-addFriendAll: "&6/as addfriend &7-&r Add a friend to a region"
|
||||
help-delFriend: "&6/as delfriend &7-&r Delete a friend from your region"
|
||||
help-delFriendAll: "&6/as delfriend &7-&r Delete a friend from a region"
|
||||
|
||||
############ Other command strings
|
||||
rent-help: "/as rent [regionname], the region you stand in will be used if not specified"
|
||||
@ -330,11 +332,19 @@ stopresell-noPermissionOther: "You don't have permission to set regions back to
|
||||
addfriend-help: "/as addfriend <player> [region], the region you stand in will be used if not specified"
|
||||
addfriend-noPermissionOther: "You don't have permission to add friends to regions that are not yours"
|
||||
addfriend-noPermission: "You don't have permission to add friends to your region"
|
||||
addfriend-notRegistered: "%0% is not registered in AreaShop"
|
||||
addfriend-successOther: "%0% has been added as friend to region %1%"
|
||||
addfriend-success: "%0% has been added as friend to your region %1%"
|
||||
addfriend-alreadyAdded: "%0% is already added as friend for this region"
|
||||
addfriend-self: "Adding the owner of the region as friend would be pointless"
|
||||
addfriend-noOwner: "You cannot add friends to a region without owner"
|
||||
|
||||
delfriend-help: "/as delfriend <player> [region], the region you stand in will be used if not specified"
|
||||
delfriend-noPermissionOther: "You don't have permission to delete friends from regions that are not yours"
|
||||
delfriend-noPermission: "You don't have permission to delete friends from your region"
|
||||
delfriend-successOther: "%0% has been deleted as friend from region %1%"
|
||||
delfriend-success: "%0% has been deleted as friend from your region %1%"
|
||||
delfriend-notAdded: "%0% is not added as friend for this region"
|
||||
delfriend-noOwner: "You cannot remove friends from a region without owner"
|
||||
|
||||
############ Sign, greeting and other strings
|
||||
timeleft-years: "%0% years"
|
||||
|
@ -11,6 +11,7 @@ import nl.evolutioncoding.areashop.commands.AddsignCommand;
|
||||
import nl.evolutioncoding.areashop.commands.BuyCommand;
|
||||
import nl.evolutioncoding.areashop.commands.CommandAreaShop;
|
||||
import nl.evolutioncoding.areashop.commands.DelCommand;
|
||||
import nl.evolutioncoding.areashop.commands.DelfriendCommand;
|
||||
import nl.evolutioncoding.areashop.commands.DelsignCommand;
|
||||
import nl.evolutioncoding.areashop.commands.FindCommand;
|
||||
import nl.evolutioncoding.areashop.commands.GroupaddCommand;
|
||||
@ -64,6 +65,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
commands.add(new TeleportCommand(plugin));
|
||||
commands.add(new SetteleportCommand(plugin));
|
||||
commands.add(new AddfriendCommand(plugin));
|
||||
commands.add(new DelfriendCommand(plugin));
|
||||
commands.add(new FindCommand(plugin));
|
||||
commands.add(new ResellCommand(plugin));
|
||||
commands.add(new StopresellCommand(plugin));
|
||||
|
@ -4,7 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -67,42 +69,47 @@ public class AddfriendCommand extends CommandAreaShop {
|
||||
} else {
|
||||
region = plugin.getFileManager().getRegion(args[2]);
|
||||
if(region == null) {
|
||||
plugin.message(sender, "addfriend-notRegistered", args[2]);
|
||||
plugin.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.addfriendall")) {
|
||||
if((region.isRentRegion() && !((RentRegion)region).isRented())
|
||||
|| (region.isBuyRegion() && !((BuyRegion)region).isSold())) {
|
||||
plugin.message(sender, "addfriend-noOwner");
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(region.getFriendList().contains(friend.getUniqueId())) {
|
||||
plugin.message(sender, "addfriend-alreadyAdded", args[1]);
|
||||
plugin.message(sender, "addfriend-alreadyAdded", friend.getName());
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
plugin.message(sender, "addfriend-self", args[1]);
|
||||
plugin.message(sender, "addfriend-self", friend.getName());
|
||||
return;
|
||||
}
|
||||
region.addFriend(friend.getUniqueId());
|
||||
region.saveRequired();
|
||||
region.updateRegionFlags();
|
||||
region.updateSigns();
|
||||
plugin.message(sender, "addfriend-successOther", args[1], region.getName());
|
||||
plugin.message(sender, "addfriend-successOther", friend.getName(), region.getName());
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.addfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
plugin.message(sender, "addfriend-success", args[1], region.getName());
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(region.getFriendList().contains(friend.getUniqueId())) {
|
||||
plugin.message(sender, "addfriend-alreadyAdded", args[1]);
|
||||
plugin.message(sender, "addfriend-alreadyAdded", friend.getName());
|
||||
return;
|
||||
}
|
||||
if(region.isOwner(friend.getUniqueId())) {
|
||||
plugin.message(sender, "addfriend-self", args[1]);
|
||||
plugin.message(sender, "addfriend-self", friend.getName());
|
||||
return;
|
||||
}
|
||||
region.addFriend(friend.getUniqueId());
|
||||
region.saveRequired();
|
||||
region.updateRegionFlags();
|
||||
region.updateSigns();
|
||||
plugin.message(sender, "addfriend-success", friend.getName(), region.getName());
|
||||
} else {
|
||||
plugin.message(sender, "addfriend-noPermissionOther");
|
||||
}
|
||||
|
132
src/nl/evolutioncoding/areashop/commands/DelfriendCommand.java
Normal file
132
src/nl/evolutioncoding/areashop/commands/DelfriendCommand.java
Normal file
@ -0,0 +1,132 @@
|
||||
package nl.evolutioncoding.areashop.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import nl.evolutioncoding.areashop.AreaShop;
|
||||
import nl.evolutioncoding.areashop.regions.BuyRegion;
|
||||
import nl.evolutioncoding.areashop.regions.GeneralRegion;
|
||||
import nl.evolutioncoding.areashop.regions.RentRegion;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class DelfriendCommand extends CommandAreaShop {
|
||||
|
||||
public DelfriendCommand(AreaShop plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandStart() {
|
||||
return "areashop delfriend";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp(CommandSender target) {
|
||||
if(target.hasPermission("areashop.delfriendall")) {
|
||||
return plugin.getLanguageManager().getLang("help-delFriendAll");
|
||||
} else if(target.hasPermission("areashop.delfriend")) {
|
||||
return plugin.getLanguageManager().getLang("help-delFriend");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void execute(CommandSender sender, Command command, String[] args) {
|
||||
if(!sender.hasPermission("areashop.delfriend") && !sender.hasPermission("areashop.delfriendall")) {
|
||||
plugin.message(sender, "delfriend-noPermission");
|
||||
return;
|
||||
}
|
||||
if(args.length < 2) {
|
||||
plugin.message(sender, "delfriend-help");
|
||||
return;
|
||||
}
|
||||
GeneralRegion region = null;
|
||||
if(args.length <= 2) {
|
||||
if (sender instanceof Player) {
|
||||
// get the region by location
|
||||
List<GeneralRegion> regions = plugin.getFileManager().getAllApplicableRegions(((Player) sender).getLocation());
|
||||
if (regions.isEmpty()) {
|
||||
plugin.message(sender, "cmd-noRegionsAtLocation");
|
||||
return;
|
||||
} else if (regions.size() > 1) {
|
||||
plugin.message(sender, "cmd-moreRegionsAtLocation");
|
||||
return;
|
||||
} else {
|
||||
region = regions.get(0);
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "cmd-automaticRegionOnlyByPlayer");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
region = plugin.getFileManager().getRegion(args[2]);
|
||||
if(region == null) {
|
||||
plugin.message(sender, "cmd-notRegistered", args[2]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(sender.hasPermission("areashop.delfriendall")) {
|
||||
if((region.isRentRegion() && !((RentRegion)region).isRented())
|
||||
|| (region.isBuyRegion() && !((BuyRegion)region).isSold())) {
|
||||
plugin.message(sender, "delfriend-noOwner");
|
||||
return;
|
||||
}
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendList().contains(friend.getUniqueId())) {
|
||||
plugin.message(sender, "delfriend-notAdded", friend.getName());
|
||||
return;
|
||||
}
|
||||
region.deleteFriend(friend.getUniqueId());
|
||||
region.saveRequired();
|
||||
region.updateRegionFlags();
|
||||
region.updateSigns();
|
||||
plugin.message(sender, "delfriend-successOther", friend.getName(), region.getName());
|
||||
} else {
|
||||
if(sender.hasPermission("areashop.delfriend") && sender instanceof Player) {
|
||||
if(region.isOwner((Player)sender)) {
|
||||
OfflinePlayer friend = Bukkit.getOfflinePlayer(args[1]);
|
||||
if(!region.getFriendList().contains(friend.getUniqueId())) {
|
||||
plugin.message(sender, "delfriend-notAdded", friend.getName());
|
||||
return;
|
||||
}
|
||||
region.deleteFriend(friend.getUniqueId());
|
||||
region.saveRequired();
|
||||
region.updateRegionFlags();
|
||||
region.updateSigns();
|
||||
plugin.message(sender, "delfriend-success", friend.getName(), region.getName());
|
||||
} else {
|
||||
plugin.message(sender, "delfriend-noPermissionOther");
|
||||
}
|
||||
} else {
|
||||
plugin.message(sender, "delfriend-noPermission");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteList(int toComplete, String[] start) {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
if(toComplete == 2) {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
result.add(player.getName());
|
||||
}
|
||||
} else if(toComplete == 3) {
|
||||
result.addAll(plugin.getFileManager().getRegionNames());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user