-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4783084
commit aa63b41
Showing
7 changed files
with
281 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/bentobox/addon/limits/commands/AdminCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* | ||
*/ | ||
package bentobox.addon.limits.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import bentobox.addon.limits.Limits; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
/** | ||
* Admin command for limits | ||
* @author tastybento | ||
* | ||
*/ | ||
public class AdminCommand extends CompositeCommand { | ||
|
||
private Limits addon; | ||
|
||
/** | ||
* Top level command | ||
* @param addon | ||
*/ | ||
public AdminCommand(Limits addon, CompositeCommand parent) { | ||
super(parent, "limits"); | ||
this.addon = addon; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#setup() | ||
*/ | ||
@Override | ||
public void setup() { | ||
this.setPermission("limits.admin.limits"); | ||
this.setOnlyPlayer(true); | ||
this.setParametersHelp("admin.limits.parameters"); | ||
this.setDescription("admin.limits.description"); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List) | ||
*/ | ||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
if (args.size() == 1) { | ||
// Asking for another player's limits | ||
// Convert name to a UUID | ||
final UUID playerUUID = getPlugin().getPlayers().getUUID(args.get(0)); | ||
if (playerUUID == null) { | ||
user.sendMessage("general.errors.unknown-player", args.get(0)); | ||
return true; | ||
} else { | ||
new LimitPanel(addon).showLimits(getWorld(), user, playerUUID); | ||
} | ||
return true; | ||
} else { | ||
showHelp(this, user); | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) { | ||
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; | ||
if (args.isEmpty()) { | ||
// Don't show every player on the server. Require at least the first letter | ||
return Optional.empty(); | ||
} | ||
List<String> options = new ArrayList<>(Util.getOnlinePlayerList(user)); | ||
return Optional.of(Util.tabLimit(options, lastArg)); | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/bentobox/addon/limits/commands/LimitPanel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* | ||
*/ | ||
package bentobox.addon.limits.commands; | ||
|
||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
|
||
import bentobox.addon.limits.Limits; | ||
import bentobox.addon.limits.objects.IslandBlockCount; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; | ||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.bentobox.util.Util; | ||
|
||
/** | ||
* Shows a panel of the blocks that are limited and their status | ||
* @author tastybento | ||
* | ||
*/ | ||
public class LimitPanel { | ||
|
||
private Limits addon; | ||
|
||
/** | ||
* @param addon - limit addon | ||
*/ | ||
public LimitPanel(Limits addon) { | ||
this.addon = addon; | ||
} | ||
|
||
public void showLimits(World world, User user, UUID target) { | ||
PanelBuilder pb = new PanelBuilder().name(user.getTranslation(world, "limits.panel-title")).user(user); | ||
// Get the island for the target | ||
Island island = addon.getIslands().getIsland(world, target); | ||
if (island == null) { | ||
user.sendMessage("general.errors.player-has-no-island"); | ||
return; | ||
} | ||
IslandBlockCount ibc = addon.getBlockLimitListener().getIsland(island.getUniqueId()); | ||
Map<Material, Integer> matLimits = addon.getBlockLimitListener().getMaterialLimits(world, island.getUniqueId()); | ||
if (matLimits.isEmpty()) { | ||
user.sendMessage("island.limits.no-limits"); | ||
return; | ||
} | ||
for (Entry<Material, Integer> en : matLimits.entrySet()) { | ||
PanelItemBuilder pib = new PanelItemBuilder(); | ||
pib.name(Util.prettifyText(en.getKey().toString())); | ||
pib.icon(en.getKey()); | ||
int count = ibc == null ? 0 : ibc.getBlockCount().getOrDefault(en.getKey(), 0); | ||
String color = count >= en.getValue() ? user.getTranslation("island.limits.max-color") : user.getTranslation("island.limits.regular-color"); | ||
pib.description(color | ||
+ user.getTranslation("island.limits.block-limit-syntax", | ||
TextVariables.NUMBER, String.valueOf(count), | ||
"[limit]", String.valueOf(en.getValue()))); | ||
pb.item(pib.build()); | ||
} | ||
pb.build(); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/bentobox/addon/limits/commands/PlayerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* | ||
*/ | ||
package bentobox.addon.limits.commands; | ||
|
||
import java.util.List; | ||
|
||
import bentobox.addon.limits.Limits; | ||
import world.bentobox.bentobox.api.commands.CompositeCommand; | ||
import world.bentobox.bentobox.api.user.User; | ||
|
||
/** | ||
* User command for limits | ||
* @author tastybento | ||
* | ||
*/ | ||
public class PlayerCommand extends CompositeCommand { | ||
|
||
private Limits addon; | ||
|
||
/** | ||
* Top level command | ||
* @param addon | ||
*/ | ||
public PlayerCommand(Limits addon, CompositeCommand parent) { | ||
super(parent, "limits"); | ||
this.addon = addon; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#setup() | ||
*/ | ||
@Override | ||
public void setup() { | ||
this.setPermission("limits.player.limits"); | ||
this.setOnlyPlayer(true); | ||
this.setParametersHelp("island.limits.parameters"); | ||
this.setDescription("island.limits.description"); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see world.bentobox.bentobox.api.commands.BentoBoxCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List) | ||
*/ | ||
@Override | ||
public boolean execute(User user, String label, List<String> args) { | ||
if (!args.isEmpty()) { | ||
showHelp(this, user); | ||
return false; | ||
} else { | ||
new LimitPanel(addon).showLimits(getWorld(), user, user.getUniqueId()); | ||
return true; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.