Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add better home list with the /homes command (with zavdav) #9

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void onEnable() {
Bukkit.getPluginCommand("hat").setExecutor(new CommandHat());
Bukkit.getPluginCommand("sethome").setExecutor(new CommandSetHome());
Bukkit.getPluginCommand("delhome").setExecutor(new CommandDelhome());
Bukkit.getPluginCommand("homes").setExecutor(new CommandHomes(plugin));
Bukkit.getPluginCommand("balance").setExecutor(new CommandBalance());
Bukkit.getPluginCommand("economy").setExecutor(new CommandEconomy());
// Bukkit.getPluginCommand("pay").setExecutor(new CommandPay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}
msg = msg.substring(0, msg.length() - 2);
commandSender.sendMessage(formatColor(msg));
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("home_use_homes"));
return true;
} else {
if (!targetPlayer.doesHomeExist(homeName)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.johnymuffin.beta.fundamentals.commands;

import org.bukkit.entity.Player;

import org.bukkit.command.CommandSender;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import com.johnymuffin.beta.fundamentals.*;
import com.johnymuffin.beta.fundamentals.player.FundamentalsPlayer;
import com.johnymuffin.beta.fundamentals.settings.*;

import java.util.Collections;
import java.util.Arrays;
import java.util.ArrayList;

import static com.johnymuffin.beta.fundamentals.util.Utils.formatColor;

public class CommandHomes implements CommandExecutor {
private Fundamentals plugin;

public CommandHomes(Fundamentals plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (!(commandSender.hasPermission("fundamentals.homes") || commandSender.isOp())) {
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("no_permission"));
return true;
}
if (!(commandSender instanceof Player)) {
commandSender.sendMessage("Sorry, console can't run this command.");
return true;
}

int page;

if (strings.length == 0) {
page = 1;
}
else {
try {
// check if the home page number provided by the user is 0
if (Integer.parseInt(strings[0]) != 0) {
page = Integer.parseInt(strings[0]);
} else {
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("homes_invalid_usage"));
return true;
}
} catch (NumberFormatException e) {
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("homes_invalid_usage"));
return true;
}
}
FundamentalsPlayer fPlayer = FundamentalsPlayerMap.getInstance().getPlayer((Player) commandSender);
ArrayList<String> homeList = fPlayer.getPlayerHomes();
Collections.sort(homeList);

if (homeList.size() == 0) {
//no entries in home list
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("home_non_recorded"));
return true;
}
int homesPerPage = FundamentalsConfig.getInstance().getConfigInteger("settings.homes-per-page");
int pageCount = (int) Math.ceil((double) homeList.size() / homesPerPage);

if (page <= pageCount) {
String message = FundamentalsLanguage.getInstance().getMessage("homes_list");
message = message.replace("%var1%", String.valueOf(page));
message = message.replace("%var2%", String.valueOf(pageCount));
commandSender.sendMessage(message);

String homes = "";
for (int i = page * homesPerPage - homesPerPage; (i < page * homesPerPage) && i < homeList.size() && homeList.get(i) != null; i++) {
String home = homeList.get(i);
if (fPlayer.isHomeInValidWorld(home)) {
homes = homes + "&a" + home + "&6, ";
} else {
homes = homes + "&4" + home + "&6, ";
}
}
homes = homes.substring(0, homes.length() - 2);
commandSender.sendMessage(formatColor(homes));
} else {
// specified page count too high
commandSender.sendMessage(FundamentalsLanguage.getInstance().getMessage("homes_invalid_usage"));
return true;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ private void write() {
generateConfigOption("settings.auto-save-time", 300);
generateConfigOption("settings.debug-level", 1);
generateConfigOption("settings.multiple-homes", 5);
generateConfigOption("settings.homes-per-page", 50);
generateConfigOption("settings.load-all-players-into-cache", false);
generateConfigOption("settings.afk.enabled", true);
generateConfigOption("settings.afk.time", 60 * 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ private void loadDefaults() {
map.put("hat_invalid", "&cYou can't put that item on your head silly!");
//Home
map.put("home_non_recorded", "&6Sorry, you have no homes on record. Please set one with /sethome");
map.put("home_not_on_record", "&6Sorry, we couldn't find a home with that name. Do /home for a list of homes");
map.put("home_not_on_record", "&6Sorry, we couldn't find a home with that name. Do /homes for a list of homes");
map.put("home_in_invalid_world", "&4Sorry, your home is in an invalid world.");
map.put("home_teleport_successfully", "&6You have been teleported to your home &b%var1%");
map.put("home_use_homes", "&6Use &a/homes&6 for a more feature rich home list.");
//Homesearch
map.put("homesearch_invalid_radius", "Please enter a valid number for radius.");
map.put("homesearch_usage", "Usage: /homesearch <username> <radius>");
Expand All @@ -58,9 +59,12 @@ private void loadDefaults() {
map.put("sethome_set_successfully", "&6Your home &b%var1% &6has been set.");
//Delhome
map.put("delhome_info", "&6Please specify a home name \"/delhome (home)\". A list of homes can be obtained with /home.");
map.put("delhome_unknown_home", "&6Sorry, we couldn't find a home with that name. Do /home to get a list of homes.");
map.put("delhome_unknown_home", "&6Sorry, we couldn't find a home with that name. Do /homes to get a list of homes.");
map.put("delhome_unknown_successful", "&6You have successfully deleted a home");
map.put("delhome_unknown_unsuccessful", "&4Sorry, an error was encountered when deleting that home. Please contact staff!");
//Homes
map.put("homes_list", "&6Home List (page &a%var1%&6/&a%var2%&6): ");
map.put("homes_invalid_usage", "&6Invalid usage: &a/homes [page number]");
//Balance
map.put("balance_successful", "&6Balance: $%var1%");
//Baltop
Expand Down
3 changes: 3 additions & 0 deletions FundamentalsCore/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ commands:
description: a home command
usage: /<command>
aliases: [dh]
homes:
description: a home command
usage: /<command>
balance:
description: a balance command
usage: /<command>
Expand Down
Loading