mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-22 00:58:04 +01:00
Implemented User class
And also made use of it in commands
This commit is contained in:
parent
90f88b4425
commit
cd40405c30
@ -352,7 +352,7 @@ invite:
|
||||
nameHasUninvitedYou: "[name] has removed the invite to join their island!"
|
||||
onlyIslandOwnerCanInvite: "Only the leader can invite!"
|
||||
removingInvite: "Removing your previous invite."
|
||||
toAcceptOrReject: "to accept or reject the invite."
|
||||
toAcceptOrReject: "/[label] [accept/reject] to accept or reject the invite."
|
||||
warningYouWillLoseIsland: "WARNING: You will lose your current island if you accept!"
|
||||
youCanInvite: "You can invite [number] more players."
|
||||
youCannotInvite: "You can't invite any more players."
|
||||
@ -602,9 +602,8 @@ sign-acidisland:
|
||||
line4: "Beware!"
|
||||
targetInPVPArea: "Target is in a no-PVP area!"
|
||||
team:
|
||||
color: "&b"
|
||||
leader-color: "&a"
|
||||
leader: " - Leader"
|
||||
leader: "&a[name] - Leader"
|
||||
member: "&b[name]"
|
||||
listingMembers: "Listing island members"
|
||||
teamchat:
|
||||
helpChat: "turn on/off team chat"
|
||||
|
@ -31,8 +31,8 @@ public abstract class CommandArgument {
|
||||
|
||||
public CommandArgument() {}
|
||||
|
||||
public abstract boolean execute(CommandSender sender, String[] args);
|
||||
public abstract Set<String> tabComplete(CommandSender sender, String[] args);
|
||||
public abstract boolean execute(User user, String[] args);
|
||||
public abstract Set<String> tabComplete(User user, String[] args);
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
@ -73,11 +73,11 @@ public abstract class CommandArgument {
|
||||
// These methods below just neaten up the code in the commands so "plugin." isn't always used
|
||||
|
||||
/**
|
||||
* @param sender
|
||||
* @param user
|
||||
* @return true if sender is a player
|
||||
*/
|
||||
protected boolean isPlayer(CommandSender sender) {
|
||||
return (sender instanceof Player);
|
||||
protected boolean isPlayer(User user) {
|
||||
return (user.getPlayer() instanceof Player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,19 +89,19 @@ public abstract class CommandArgument {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param user
|
||||
* @return UUID of player's team leader
|
||||
*/
|
||||
protected UUID getTeamLeader(Player player) {
|
||||
return plugin.getIslands().getTeamLeader(player.getUniqueId());
|
||||
protected UUID getTeamLeader(User user) {
|
||||
return plugin.getIslands().getTeamLeader(user.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player
|
||||
* @param user
|
||||
* @return set of UUIDs of all team members
|
||||
*/
|
||||
protected Set<UUID> getMembers(Player player) {
|
||||
return plugin.getIslands().getMembers(player.getUniqueId());
|
||||
protected Set<UUID> getMembers(User user) {
|
||||
return plugin.getIslands().getMembers(user.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
|
||||
|
||||
if (subCommand != null) { // check if this subcommand exists
|
||||
if (!subCommand.hasSubCommmands()) { // if it has not any subcommands
|
||||
subCommand.execute(sender, args); //TODO: "cut" the args to only send the needed ones
|
||||
subCommand.execute(User.getInstance(sender), args); //TODO: "cut" the args to only send the needed ones
|
||||
}
|
||||
// else continue the loop
|
||||
// TODO: adapt this part to make it works with arguments that are not subcommands
|
||||
|
168
src/main/java/us/tastybento/bskyblock/api/commands/User.java
Normal file
168
src/main/java/us/tastybento/bskyblock/api/commands/User.java
Normal file
@ -0,0 +1,168 @@
|
||||
package us.tastybento.bskyblock.api.commands;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
|
||||
public class User {
|
||||
|
||||
private static Map<UUID, User> users = new HashMap<>();
|
||||
/**
|
||||
* Get an instance of User from a CommandSender
|
||||
* @param sender
|
||||
* @return user
|
||||
*/
|
||||
public static User getInstance(CommandSender sender) {
|
||||
if (sender instanceof Player) {
|
||||
return getInstance((Player)sender);
|
||||
}
|
||||
// Console
|
||||
return new User(sender);
|
||||
}
|
||||
/**
|
||||
* Get an instance of User from a Player object
|
||||
* @param player
|
||||
* @return user
|
||||
*/
|
||||
public static User getInstance(Player player) {
|
||||
if (player == null)
|
||||
return null;
|
||||
if (users.containsKey(player.getUniqueId())) {
|
||||
return users.get(player.getUniqueId());
|
||||
}
|
||||
return new User(player);
|
||||
}
|
||||
/**
|
||||
* Get an instance of User from a UUID
|
||||
* @param uuid
|
||||
* @return user
|
||||
*/
|
||||
public static User getInstance(UUID uuid) {
|
||||
if (users.containsKey(uuid)) {
|
||||
return users.get(uuid);
|
||||
}
|
||||
// Return player, or null if they are not online
|
||||
return new User(uuid);
|
||||
}
|
||||
/**
|
||||
* Removes this player from the User cache
|
||||
* @param player
|
||||
*/
|
||||
public static void removePlayer(Player player) {
|
||||
users.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
private final Player player;
|
||||
|
||||
private final UUID playerUUID;
|
||||
|
||||
private final BSkyBlock plugin = BSkyBlock.getPlugin();
|
||||
|
||||
private final CommandSender sender;
|
||||
|
||||
private User(CommandSender sender) {
|
||||
this.player = null;
|
||||
this.playerUUID = null;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
private User(Player player) {
|
||||
this.player = player;
|
||||
this.sender = player;
|
||||
this.playerUUID = player.getUniqueId();
|
||||
users.put(player.getUniqueId(), this);
|
||||
}
|
||||
|
||||
private User(UUID playerUUID) {
|
||||
this.player = Bukkit.getPlayer(playerUUID);
|
||||
this.playerUUID = playerUUID;
|
||||
this.sender = null;
|
||||
}
|
||||
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return player.getEffectivePermissions();
|
||||
}
|
||||
|
||||
public PlayerInventory getInventory() {
|
||||
return player.getInventory();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return player.getLocation();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player
|
||||
*/
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public CommandSender getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public UUID getUniqueId() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
public boolean hasPermission(String string) {
|
||||
return player.hasPermission(string);
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return player == null ? false : player.isOnline();
|
||||
}
|
||||
|
||||
public boolean isOp() {
|
||||
return player.isOp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message to sender if message is not empty. Does not include color codes or spaces
|
||||
* @param reference - language file reference. May be preceded with color codes.
|
||||
* @param variables - CharSequence target, replacement pairs
|
||||
*/
|
||||
public void sendMessage(String reference, String... variables ) {
|
||||
String message = ChatColor.getLastColors(reference) + plugin.getLocale(sender).get(ChatColor.stripColor(reference));
|
||||
if (variables.length > 1) {
|
||||
for (int i = 0; i < variables.length; i+=2) {
|
||||
message.replace(variables[i], variables[i+1]);
|
||||
}
|
||||
}
|
||||
if (!ChatColor.stripColor(message).trim().isEmpty()) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage(message);
|
||||
} else {
|
||||
// TODO: Offline message
|
||||
// Save this message so the player can see it later
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setGameMode(GameMode mode) {
|
||||
player.setGameMode(mode);
|
||||
|
||||
}
|
||||
|
||||
public void teleport(Location location) {
|
||||
player.teleport(location);
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ package us.tastybento.bskyblock.api.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@ -18,12 +19,30 @@ public class IslandBaseEvent extends Event implements Cancellable{
|
||||
private boolean cancelled;
|
||||
|
||||
private final Island island;
|
||||
private final UUID playerUUID;
|
||||
private final boolean admin;
|
||||
private final Location location;
|
||||
|
||||
public IslandBaseEvent(Island island) {
|
||||
super();
|
||||
this.island = island;
|
||||
this.playerUUID = island == null ? null : island.getOwner();
|
||||
this.admin = false;
|
||||
this.location = island == null ? null : island.getCenter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param island
|
||||
* @param playerUUID
|
||||
* @param admin
|
||||
* @param location
|
||||
*/
|
||||
public IslandBaseEvent(Island island){
|
||||
public IslandBaseEvent(Island island, UUID playerUUID, boolean admin, Location location) {
|
||||
super();
|
||||
this.island = island;
|
||||
this.playerUUID = playerUUID;
|
||||
this.admin = admin;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,6 +59,27 @@ public class IslandBaseEvent extends Event implements Cancellable{
|
||||
return this.getOwner();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the playerUUID
|
||||
*/
|
||||
public UUID getPlayerUUID() {
|
||||
return playerUUID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the admin
|
||||
*/
|
||||
public boolean isAdmin() {
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the location
|
||||
*/
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
|
@ -13,7 +13,8 @@ import us.tastybento.bskyblock.database.objects.Island;
|
||||
* @author tastybento
|
||||
* @since 1.0
|
||||
*/
|
||||
public class IslandEvent extends IslandBaseEvent {
|
||||
public class IslandEvent {
|
||||
|
||||
public enum Reason {
|
||||
CREATE,
|
||||
CREATED,
|
||||
@ -27,38 +28,78 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
UNLOCK,
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
/**
|
||||
* Player involved with this event
|
||||
*/
|
||||
private final UUID player;
|
||||
/**
|
||||
* True if this is an admin action
|
||||
*/
|
||||
private final boolean admin;
|
||||
/**
|
||||
* Reason for this event
|
||||
*/
|
||||
private final Reason reason;
|
||||
|
||||
/**
|
||||
* Location related to the event
|
||||
*/
|
||||
private Location location;
|
||||
|
||||
private IslandEvent(Island island, UUID player, boolean admin, Reason reason, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island);
|
||||
this.player = player;
|
||||
this.admin = admin;
|
||||
this.reason = reason;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public static IslandEventBuilder builder() {
|
||||
return new IslandEventBuilder();
|
||||
}
|
||||
|
||||
|
||||
public static class IslandCreateEvent extends IslandBaseEvent {
|
||||
private IslandCreateEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandCreatedEvent extends IslandBaseEvent {
|
||||
private IslandCreatedEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandDeleteEvent extends IslandBaseEvent {
|
||||
private IslandDeleteEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandDeletedEvent extends IslandBaseEvent {
|
||||
private IslandDeletedEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandEnterEvent extends IslandBaseEvent {
|
||||
private IslandEnterEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandExitEvent extends IslandBaseEvent {
|
||||
private IslandExitEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandLockEvent extends IslandBaseEvent {
|
||||
private IslandLockEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandUnlockEvent extends IslandBaseEvent {
|
||||
private IslandUnlockEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandResetEvent extends IslandBaseEvent {
|
||||
private IslandResetEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandResettedEvent extends IslandBaseEvent {
|
||||
private IslandResettedEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
public static class IslandGeneralEvent extends IslandBaseEvent {
|
||||
private IslandGeneralEvent(Island island, UUID player, boolean admin, Location location) {
|
||||
// Final variables have to be declared in the constuctor
|
||||
super(island, player, admin, location);
|
||||
}
|
||||
}
|
||||
|
||||
public static class IslandEventBuilder {
|
||||
// Here field are NOT final. They are just used for the building.
|
||||
private Island island;
|
||||
@ -66,12 +107,12 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
private Reason reason = Reason.UNKNOWN;
|
||||
private boolean admin;
|
||||
private Location location;
|
||||
|
||||
|
||||
public IslandEventBuilder island(Island island) {
|
||||
this.island = island;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* True if this is an admin driven event
|
||||
* @param admin
|
||||
@ -90,7 +131,7 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param player involved in the event
|
||||
* @return
|
||||
@ -99,41 +140,38 @@ public class IslandEvent extends IslandBaseEvent {
|
||||
this.player = player;
|
||||
return this;
|
||||
}
|
||||
|
||||
public IslandEvent build() {
|
||||
return new IslandEvent(island, player, admin, reason, location);
|
||||
}
|
||||
|
||||
public IslandEventBuilder location(Location location) {
|
||||
this.location = location;
|
||||
public IslandEventBuilder location(Location center) {
|
||||
this.location = center;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
public IslandBaseEvent build() {
|
||||
switch (reason) {
|
||||
case CREATE:
|
||||
return new IslandCreateEvent(island, player, admin, location);
|
||||
case CREATED:
|
||||
return new IslandCreatedEvent(island, player, admin, location);
|
||||
case DELETE:
|
||||
return new IslandDeleteEvent(island, player, admin, location);
|
||||
case DELETED:
|
||||
return new IslandDeletedEvent(island, player, admin, location);
|
||||
case ENTER:
|
||||
return new IslandEnterEvent(island, player, admin, location);
|
||||
case EXIT:
|
||||
return new IslandExitEvent(island, player, admin, location);
|
||||
case LOCK:
|
||||
return new IslandLockEvent(island, player, admin, location);
|
||||
case RESET:
|
||||
return new IslandResetEvent(island, player, admin, location);
|
||||
case RESETTED:
|
||||
return new IslandResettedEvent(island, player, admin, location);
|
||||
case UNLOCK:
|
||||
return new IslandUnlockEvent(island, player, admin, location);
|
||||
default:
|
||||
return new IslandGeneralEvent(island, player, admin, location);
|
||||
|
||||
/**
|
||||
* @return the player involved with this event
|
||||
*/
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this is an admin action
|
||||
*/
|
||||
public boolean isAdmin() {
|
||||
return admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the reason for this team event
|
||||
*/
|
||||
public Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,11 +2,8 @@ package us.tastybento.bskyblock.commands.admin;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class AdminVersionCommand extends CommandArgument {
|
||||
|
||||
@ -15,14 +12,13 @@ public class AdminVersionCommand extends CommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
sender.sendMessage(Bukkit.getBukkitVersion());
|
||||
sender.sendMessage("BSB " + BSkyBlock.getPlugin().getDescription().getVersion());
|
||||
return true;
|
||||
public boolean execute(User user, String[] args) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,9 @@ package us.tastybento.bskyblock.commands.island;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class IslandAboutCommand extends CommandArgument {
|
||||
|
||||
@ -14,41 +13,41 @@ public class IslandAboutCommand extends CommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
sender.sendMessage("About " + BSkyBlock.getPlugin().getDescription().getName() + " v" + BSkyBlock.getPlugin().getDescription().getVersion() + ":");
|
||||
sender.sendMessage("Copyright (c) 2017 - 2018 tastybento, Poslovitch");
|
||||
sender.sendMessage("All rights reserved.");
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage("Redistribution and use in source and binary forms, with or without");
|
||||
sender.sendMessage("modification, are permitted provided that the following conditions are met:");
|
||||
public boolean execute(User user, String[] args) {
|
||||
user.sendMessage("About " + BSkyBlock.getPlugin().getDescription().getName() + " v" + BSkyBlock.getPlugin().getDescription().getVersion() + ":");
|
||||
user.sendMessage("Copyright (c) 2017 - 2018 tastybento, Poslovitch");
|
||||
user.sendMessage("All rights reserved.");
|
||||
user.sendMessage("");
|
||||
user.sendMessage("Redistribution and use in source and binary forms, with or without");
|
||||
user.sendMessage("modification, are permitted provided that the following conditions are met:");
|
||||
|
||||
sender.sendMessage(" * Redistributions of source code must retain the above copyright notice,");
|
||||
sender.sendMessage(" this list of conditions and the following disclaimer.");
|
||||
user.sendMessage(" * Redistributions of source code must retain the above copyright notice,");
|
||||
user.sendMessage(" this list of conditions and the following disclaimer.");
|
||||
|
||||
sender.sendMessage(" * Redistributions in binary form must reproduce the above copyright");
|
||||
sender.sendMessage(" notice, this list of conditions and the following disclaimer in the");
|
||||
sender.sendMessage(" documentation and/or other materials provided with the distribution.");
|
||||
user.sendMessage(" * Redistributions in binary form must reproduce the above copyright");
|
||||
user.sendMessage(" notice, this list of conditions and the following disclaimer in the");
|
||||
user.sendMessage(" documentation and/or other materials provided with the distribution.");
|
||||
|
||||
sender.sendMessage(" * Neither the name of the BSkyBlock team nor the names of its");
|
||||
sender.sendMessage(" contributors may be used to endorse or promote products derived from");
|
||||
sender.sendMessage(" this software without specific prior written permission.");
|
||||
user.sendMessage(" * Neither the name of the BSkyBlock team nor the names of its");
|
||||
user.sendMessage(" contributors may be used to endorse or promote products derived from");
|
||||
user.sendMessage(" this software without specific prior written permission.");
|
||||
|
||||
sender.sendMessage("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"");
|
||||
sender.sendMessage("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE");
|
||||
sender.sendMessage("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE");
|
||||
sender.sendMessage("ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
|
||||
sender.sendMessage("LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
|
||||
sender.sendMessage("CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
|
||||
sender.sendMessage("SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS");
|
||||
sender.sendMessage("INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
|
||||
sender.sendMessage("CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)");
|
||||
sender.sendMessage("ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE");
|
||||
sender.sendMessage("POSSIBILITY OF SUCH DAMAGE. ");
|
||||
user.sendMessage("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"");
|
||||
user.sendMessage("AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE");
|
||||
user.sendMessage("IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE");
|
||||
user.sendMessage("ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
|
||||
user.sendMessage("LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
|
||||
user.sendMessage("CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
|
||||
user.sendMessage("SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS");
|
||||
user.sendMessage("INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
|
||||
user.sendMessage("CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)");
|
||||
user.sendMessage("ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE");
|
||||
user.sendMessage("POSSIBILITY OF SUCH DAMAGE. ");
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User sender, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.managers.island.NewIsland;
|
||||
@ -29,18 +29,18 @@ public class IslandCreateCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Player player = (Player)user;
|
||||
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.create")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
}
|
||||
if (getIslands().hasIsland(player.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.already-have-island"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.already-have-island");
|
||||
}
|
||||
if (inTeam(player)) {
|
||||
return false;
|
||||
@ -53,7 +53,7 @@ public class IslandCreateCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
@ -28,18 +28,18 @@ public class IslandGoCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Player player = (Player)user;
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.home")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
if (!getIslands().hasIsland(player.getUniqueId())) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-island");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1 && NumberUtils.isDigits(args[0])) {
|
||||
@ -60,7 +60,7 @@ public class IslandGoCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.managers.island.NewIsland;
|
||||
@ -23,25 +23,25 @@ public class IslandResetCommand extends CommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Player player = (Player)user;
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.reset")) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.no-permission"));
|
||||
user.sendMessage("general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
if (!getIslands().hasIsland(player.getUniqueId())) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.no-island"));
|
||||
user.sendMessage("general.errors.no-island");
|
||||
return true;
|
||||
}
|
||||
if (!getIslands().isOwner(player.getUniqueId())) {
|
||||
return false;
|
||||
}
|
||||
if (inTeam(player)) {
|
||||
sender.sendMessage(getLocale(sender).get("island.reset.MustRemovePlayers"));
|
||||
user.sendMessage("island.reset.MustRemovePlayers");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -65,14 +65,14 @@ public class IslandResetCommand extends CommandArgument {
|
||||
.build();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Could not create island for player.");
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(sender).get("general.errors.general"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.general");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
@ -27,26 +27,26 @@ public class IslandResetnameCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Player player = (Player)user;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getIslands().hasIsland(playerUUID)) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-island");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getIslands().isOwner(playerUUID)) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.not-leader");
|
||||
return true;
|
||||
}
|
||||
// Explain command
|
||||
@ -61,11 +61,11 @@ public class IslandResetnameCommand extends CommandArgument {
|
||||
|
||||
// Check if the name isn't too short or too long
|
||||
if (name.length() < Settings.nameMinLength) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.too-short").replace("[length]", String.valueOf(Settings.nameMinLength)));
|
||||
user.sendMessage("general.errors.too-short", "[length]", String.valueOf(Settings.nameMinLength));
|
||||
return true;
|
||||
}
|
||||
if (name.length() > Settings.nameMaxLength) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.too-long").replace("[length]", String.valueOf(Settings.nameMaxLength)));
|
||||
user.sendMessage("general.errors.too-long", "[length]", String.valueOf(Settings.nameMaxLength));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ public class IslandResetnameCommand extends CommandArgument {
|
||||
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
else getIslands().getIsland(playerUUID).setName(name);
|
||||
|
||||
sender.sendMessage(getLocale(sender).get("general.success"));
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ public class IslandResetnameCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
|
||||
@ -18,56 +17,55 @@ public class IslandSethomeCommand extends CommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.sethome")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if (!user.hasPermission(Settings.PERMPREFIX + "island.sethome")) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
// Check island
|
||||
if (plugin.getIslands().getIsland(player.getUniqueId()) == null) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-island"));
|
||||
if (plugin.getIslands().getIsland(user.getUniqueId()) == null) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-island");
|
||||
return true;
|
||||
}
|
||||
if (!plugin.getIslands().playerIsOnIsland(player)) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NotOnIsland"));
|
||||
if (!plugin.getIslands().playerIsOnIsland(user.getPlayer())) {
|
||||
user.sendMessage(ChatColor.RED + "sethome.error.NotOnIsland");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
// island sethome
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation());
|
||||
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation());
|
||||
user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
|
||||
} else if (args.length == 1) {
|
||||
// Dynamic home sizes with permissions
|
||||
int maxHomes = Util.getPermValue(player, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
|
||||
if (maxHomes > 1) {
|
||||
// Check the number given is a number
|
||||
int number = 0;
|
||||
try {
|
||||
number = Integer.valueOf(args[0]);
|
||||
if (number < 1 || number > maxHomes) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
|
||||
user.sendMessage("sethome.error.NumHomes", "[max]", String.valueOf(maxHomes));
|
||||
} else {
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation(), number);
|
||||
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation(), number);
|
||||
user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
|
||||
user.sendMessage(ChatColor.RED + "sethome.error.NumHomes", "[max]", String.valueOf(maxHomes));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-permission"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
/**
|
||||
@ -27,32 +27,32 @@ public class IslandSetnameCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
Player player = (Player)user;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getIslands().hasIsland(playerUUID)) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-island");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getIslands().isOwner(playerUUID)) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.not-leader");
|
||||
return true;
|
||||
}
|
||||
// Resets the island name
|
||||
getIslands().getIsland(playerUUID).setName(null);
|
||||
|
||||
sender.sendMessage(getLocale(sender).get("general.success"));
|
||||
user.sendMessage("general.success");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ public class IslandSetnameCommand extends CommandArgument {
|
||||
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.CommandArgument;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
|
||||
public abstract class AbstractIslandTeamCommandArgument extends CommandArgument {
|
||||
@ -26,23 +26,19 @@ public abstract class AbstractIslandTeamCommandArgument extends CommandArgument
|
||||
protected Set<UUID> kickingPlayers = new HashSet<>();
|
||||
|
||||
// TODO: It would be good if these could be auto-provided
|
||||
protected CommandSender sender;
|
||||
protected Player player;
|
||||
protected UUID playerUUID;
|
||||
protected User user;
|
||||
|
||||
public AbstractIslandTeamCommandArgument(String label, String... aliases) {
|
||||
super(label,aliases);
|
||||
}
|
||||
|
||||
protected boolean checkTeamPerm() {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return false;
|
||||
}
|
||||
player = (Player)sender;
|
||||
playerUUID = player.getUniqueId();
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "team")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -6,8 +6,8 @@ import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -20,25 +20,26 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// Check team perm and get variables set
|
||||
if (!checkTeamPerm()) return true;
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if(!inviteList.containsKey(playerUUID))
|
||||
return true;
|
||||
// Check if player has been invited
|
||||
if (!inviteList.containsKey(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.NoOneInvitedYou"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.NoOneInvitedYou");
|
||||
return true;
|
||||
}
|
||||
// Check if player is already in a team
|
||||
if (getPlayers().inTeam(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouAreAlreadyOnATeam"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.YouAreAlreadyOnATeam");
|
||||
return true;
|
||||
}
|
||||
// Get the team leader
|
||||
UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID);
|
||||
if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.InvalidInvite"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.InvalidInvite");
|
||||
inviteList.remove(playerUUID);
|
||||
return true;
|
||||
}
|
||||
@ -58,38 +59,37 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
|
||||
plugin.getLogger().info("DEBUG: Removing player from invite list");
|
||||
inviteList.remove(playerUUID);
|
||||
// Put player into Spectator mode
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
user.setGameMode(GameMode.SPECTATOR);
|
||||
// Get the player's island - may be null if the player has no island
|
||||
Island island = getIslands().getIsland(playerUUID);
|
||||
// Get the team's island
|
||||
Island teamIsland = getIslands().getIsland(prospectiveTeamLeaderUUID);
|
||||
// Clear the player's inventory
|
||||
player.getInventory().clear();
|
||||
user.getInventory().clear();
|
||||
// Move player to team's island
|
||||
Location newHome = getIslands().getSafeHomeLocation(prospectiveTeamLeaderUUID, 1);
|
||||
player.teleport(newHome);
|
||||
user.teleport(newHome);
|
||||
// Remove player as owner of the old island
|
||||
getIslands().removePlayer(playerUUID);
|
||||
// Add the player as a team member of the new island
|
||||
getIslands().setJoinTeam(teamIsland, playerUUID);
|
||||
// Set the player's home
|
||||
getPlayers().setHomeLocation(playerUUID, player.getLocation());
|
||||
getPlayers().setHomeLocation(playerUUID, user.getLocation());
|
||||
// Delete the old island
|
||||
getIslands().deleteIsland(island, true);
|
||||
// Set the cooldown
|
||||
setResetWaitTime(player);
|
||||
setResetWaitTime(user.getPlayer());
|
||||
// Reset deaths
|
||||
if (Settings.teamJoinDeathReset) {
|
||||
getPlayers().setDeaths(playerUUID, 0);
|
||||
}
|
||||
// Put player back into normal mode
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
user.setGameMode(GameMode.SURVIVAL);
|
||||
|
||||
player.sendMessage(ChatColor.GREEN + getLocale(sender).get("invite.youHaveJoinedAnIsland").replace("[label]", Settings.ISLANDCOMMAND));
|
||||
|
||||
if (plugin.getServer().getPlayer(inviteList.get(playerUUID)) != null) {
|
||||
plugin.getServer().getPlayer(inviteList.get(playerUUID)).sendMessage(
|
||||
ChatColor.GREEN + getLocale(sender).get("invite.hasJoinedYourIsland").replace("[name]", player.getName()));
|
||||
user.sendMessage(ChatColor.GREEN + "invite.youHaveJoinedAnIsland", "[label]", Settings.ISLANDCOMMAND);
|
||||
User inviter = User.getInstance(inviteList.get(playerUUID));
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage(ChatColor.GREEN + "invite.hasJoinedYourIsland", "[name]", user.getName());
|
||||
}
|
||||
getIslands().save(false);
|
||||
if (DEBUG)
|
||||
@ -99,7 +99,7 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
|
||||
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
|
||||
@ -16,9 +16,10 @@ public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// Check team perm and get variables set
|
||||
if (!checkTeamPerm()) return true;
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Reject /island reject
|
||||
if (inviteList.containsKey(playerUUID)) {
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
@ -32,24 +33,25 @@ public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument
|
||||
if (event.isCancelled()) return true;
|
||||
|
||||
// Remove this player from the global invite list
|
||||
inviteList.remove(player.getUniqueId());
|
||||
player.sendMessage(ChatColor.GREEN + getLocale(playerUUID).get("reject.youHaveRejectedInvitation"));
|
||||
inviteList.remove(user.getUniqueId());
|
||||
user.sendMessage(ChatColor.GREEN + "reject.youHaveRejectedInvitation");
|
||||
// If the leader is online tell them directly
|
||||
// about the rejection
|
||||
if (Bukkit.getPlayer(inviteList.get(playerUUID)) != null) {
|
||||
Bukkit.getPlayer(inviteList.get(playerUUID)).sendMessage(
|
||||
ChatColor.RED + getLocale(playerUUID).get("reject.nameHasRejectedInvite").replace("[name]", player.getName()));
|
||||
User inviter = User.getInstance(inviteList.get(playerUUID));
|
||||
if (inviter != null) {
|
||||
inviter.sendMessage(
|
||||
ChatColor.RED + "reject.nameHasRejectedInvite", "[name]", user.getName());
|
||||
}
|
||||
|
||||
} else {
|
||||
// Someone typed /island reject and had not been invited
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("reject.youHaveNotBeenInvited"));
|
||||
user.sendMessage(ChatColor.RED + "reject.youHaveNotBeenInvited");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -2,24 +2,25 @@ package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
|
||||
public class IslandLeaveCommand extends AbstractIslandTeamCommandArgument {
|
||||
|
||||
public IslandLeaveCommand(String label, String[] aliases) {
|
||||
super(label, aliases);
|
||||
// TODO Auto-generated constructor stub
|
||||
public IslandLeaveCommand() {
|
||||
super("leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -5,9 +5,9 @@ import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -22,10 +22,10 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// Check team perm and get variables set
|
||||
if (!checkTeamPerm()) return true;
|
||||
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: executing team command for " + playerUUID);
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
@ -37,11 +37,11 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
|
||||
.build();
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return true;
|
||||
UUID teamLeaderUUID = getTeamLeader(player);
|
||||
Set<UUID> teamMembers = getMembers(player);
|
||||
UUID teamLeaderUUID = getTeamLeader(user);
|
||||
Set<UUID> teamMembers = getMembers(user);
|
||||
if (teamLeaderUUID.equals(playerUUID)) {
|
||||
int maxSize = Settings.maxTeamSize;
|
||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
|
||||
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
|
||||
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
|
||||
maxSize = Settings.maxTeamSize;
|
||||
@ -51,7 +51,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
|
||||
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
|
||||
if (spl.length > 1) {
|
||||
if (!NumberUtils.isDigits(spl[1])) {
|
||||
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
plugin.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
} else {
|
||||
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
|
||||
}
|
||||
@ -63,27 +63,27 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
|
||||
}
|
||||
|
||||
if (teamMembers.size() < maxSize) {
|
||||
sender.sendMessage(getLocale(sender).get("invite.youCanInvite").replace("[number]", String.valueOf(maxSize - teamMembers.size())));
|
||||
user.sendMessage("invite.youCanInvite", "[number]", String.valueOf(maxSize - teamMembers.size()));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.YourIslandIsFull");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(getLocale(sender).get("team.listingMembers"));
|
||||
user.sendMessage("team.listingMembers");
|
||||
// Display members in the list
|
||||
for (UUID m : teamMembers) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: member " + m);
|
||||
if (teamLeaderUUID.equals(m)) {
|
||||
sender.sendMessage(getLocale(sender).get("team.leader-color") + getPlayers().getName(m) + getLocale(sender).get("team.leader"));
|
||||
user.sendMessage("team.leader", "[name]", getPlayers().getName(m));
|
||||
} else {
|
||||
sender.sendMessage(getLocale(sender).get("team.color") + getPlayers().getName(m));
|
||||
user.sendMessage("team.member", "[name]", getPlayers().getName(m));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,9 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -24,25 +23,25 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// Check team perm and get variables set
|
||||
if (!checkTeamPerm()) return true;
|
||||
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Player issuing the command must have an island
|
||||
if (!getPlayers().hasIsland(playerUUID)) {
|
||||
// If the player is in a team, they are not the leader
|
||||
if (getPlayers().inTeam(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.not-leader");
|
||||
}
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouMustHaveIslandToInvite"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.YouMustHaveIslandToInvite");
|
||||
}
|
||||
if (args.length == 0 || args.length > 1) {
|
||||
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
|
||||
if (inviteList.containsKey(playerUUID)) {
|
||||
OfflinePlayer inviter = plugin.getServer().getOfflinePlayer(inviteList.get(playerUUID));
|
||||
player.sendMessage(ChatColor.GOLD + getLocale(sender).get("invite.nameHasInvitedYou").replace("[name]", inviter.getName()));
|
||||
user.sendMessage(ChatColor.GOLD + "invite.nameHasInvitedYou", "[name]", inviter.getName());
|
||||
} else {
|
||||
player.sendMessage(ChatColor.GOLD + getLocale(sender).get("help.island.invite"));
|
||||
user.sendMessage(ChatColor.GOLD + "help.island.invite");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -50,36 +49,36 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
|
||||
// Only online players can be invited
|
||||
UUID invitedPlayerUUID = getPlayers().getUUID(args[0]);
|
||||
if (invitedPlayerUUID == null) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.offline-player");
|
||||
return true;
|
||||
}
|
||||
Player invitedPlayer = plugin.getServer().getPlayer(invitedPlayerUUID);
|
||||
if (invitedPlayer == null) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
|
||||
User invitedPlayer = User.getInstance(invitedPlayerUUID);
|
||||
if (!invitedPlayer.isOnline()) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.offline-player");
|
||||
return true;
|
||||
}
|
||||
// Player cannot invite themselves
|
||||
if (playerUUID.equals(invitedPlayerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouCannotInviteYourself"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.YouCannotInviteYourself");
|
||||
return true;
|
||||
}
|
||||
// Check if this player can be invited to this island, or
|
||||
// whether they are still on cooldown
|
||||
long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(playerUUID));
|
||||
if (time > 0 && !player.isOp()) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.CoolDown").replace("[time]", String.valueOf(time)));
|
||||
if (time > 0 && !user.isOp()) {
|
||||
user.sendMessage(ChatColor.RED + "invite.error.CoolDown", "[time]", String.valueOf(time));
|
||||
return true;
|
||||
}
|
||||
// Player cannot invite someone already on a team
|
||||
if (getPlayers().inTeam(invitedPlayerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.ThatPlayerIsAlreadyInATeam"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.ThatPlayerIsAlreadyInATeam");
|
||||
return true;
|
||||
}
|
||||
Set<UUID> teamMembers = getMembers(player);
|
||||
Set<UUID> teamMembers = getMembers(user);
|
||||
// Check if player has space on their team
|
||||
int maxSize = Settings.maxTeamSize;
|
||||
// Dynamic team sizes with permissions
|
||||
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
|
||||
for (PermissionAttachmentInfo perms : user.getEffectivePermissions()) {
|
||||
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
|
||||
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
|
||||
maxSize = Settings.maxTeamSize;
|
||||
@ -89,7 +88,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
|
||||
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
|
||||
if (spl.length > 1) {
|
||||
if (!NumberUtils.isDigits(spl[1])) {
|
||||
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
plugin.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
} else {
|
||||
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
|
||||
}
|
||||
@ -104,7 +103,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
|
||||
// Players can only have one invite one at a time - interesting
|
||||
if (inviteList.containsValue(playerUUID)) {
|
||||
inviteList.inverse().remove(playerUUID);
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.removingInvite"));
|
||||
user.sendMessage(ChatColor.RED + "invite.removingInvite");
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
TeamEvent event = TeamEvent.builder()
|
||||
@ -117,27 +116,26 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
|
||||
// Put the invited player (key) onto the list with inviter (value)
|
||||
// If someone else has invited a player, then this invite will overwrite the previous invite!
|
||||
inviteList.put(invitedPlayerUUID, playerUUID);
|
||||
player.sendMessage(getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[0]));
|
||||
user.sendMessage("invite.inviteSentTo", "[name]", args[0]);
|
||||
// Send message to online player
|
||||
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD + getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
|
||||
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD +
|
||||
"/" + getLabel() + " [accept/reject]" + " " + getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject"));
|
||||
if (getPlayers().hasIsland(invitedPlayerUUID)) {
|
||||
invitedPlayer.sendMessage(ChatColor.GOLD + "invite.nameHasInvitedYou", "[name]", user.getName());
|
||||
invitedPlayer.sendMessage(ChatColor.GOLD + "invite.toAcceptOrReject", "[label]", getLabel());
|
||||
if (getPlayers().hasIsland(invitedPlayer.getUniqueId())) {
|
||||
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.RED + getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland"));
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull"));
|
||||
user.sendMessage(ChatColor.RED + "invite.error.YourIslandIsFull");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
if (args.length == 0 || !(sender instanceof Player)) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
if (args.length == 0 || !isPlayer(user)) {
|
||||
// Don't show every player on the server. Require at least the first letter
|
||||
return null;
|
||||
}
|
||||
return new HashSet<>(Util.getOnlinePlayerList((Player) sender));
|
||||
return new HashSet<>(Util.getOnlinePlayerList(user));
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,6 @@
|
||||
package us.tastybento.bskyblock.commands.island.teams;
|
||||
|
||||
import java.util.Set;
|
||||
public class IslandTeamKickCommand {
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class IslandTeamKickCommand extends AbstractIslandTeamCommandArgument {
|
||||
|
||||
public IslandTeamKickCommand(String label, String[] aliases) {
|
||||
super(label, aliases);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
@ -6,10 +6,9 @@ import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -22,9 +21,10 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
public boolean execute(User user, String[] args) {
|
||||
// Check team perm and get variables set
|
||||
if (!checkTeamPerm()) return true;
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
// Can use if in a team
|
||||
boolean inTeam = plugin.getPlayers().inTeam(playerUUID);
|
||||
UUID teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID);
|
||||
@ -34,23 +34,23 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
plugin.getLogger().info("DEBUG: arg[0] = " + args[0]);
|
||||
UUID targetUUID = getPlayers().getUUID(args[0]);
|
||||
if (targetUUID == null) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("general.errors.unknown-player"));
|
||||
user.sendMessage(ChatColor.RED + "general.errors.unknown-player");
|
||||
return true;
|
||||
}
|
||||
if (!getPlayers().inTeam(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorYouMustBeInTeam"));
|
||||
user.sendMessage(ChatColor.RED + "makeleader.errorYouMustBeInTeam");
|
||||
return true;
|
||||
}
|
||||
if (!teamLeaderUUID.equals(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorNotYourIsland"));
|
||||
user.sendMessage(ChatColor.RED + "makeleader.errorNotYourIsland");
|
||||
return true;
|
||||
}
|
||||
if (targetUUID.equals(playerUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorGeneralError"));
|
||||
user.sendMessage(ChatColor.RED + "makeleader.errorGeneralError");
|
||||
return true;
|
||||
}
|
||||
if (!plugin.getIslands().getMembers(playerUUID).contains(targetUUID)) {
|
||||
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorThatPlayerIsNotInTeam"));
|
||||
user.sendMessage(ChatColor.RED + "makeleader.errorThatPlayerIsNotInTeam");
|
||||
return true;
|
||||
}
|
||||
// Fire event so add-ons can run commands, etc.
|
||||
@ -60,14 +60,14 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
|
||||
// target is the new leader
|
||||
getIslands().getIsland(playerUUID).setOwner(targetUUID);
|
||||
player.sendMessage(ChatColor.GREEN
|
||||
+ getLocale(playerUUID).get("makeleader.nameIsNowTheOwner").replace("[name]", getPlayers().getName(targetUUID)));
|
||||
user.sendMessage(ChatColor.GREEN
|
||||
+ "makeleader.nameIsNowTheOwner", "[name]", getPlayers().getName(targetUUID));
|
||||
|
||||
// Check if online
|
||||
Player target = plugin.getServer().getPlayer(targetUUID);
|
||||
User target = User.getInstance(targetUUID);
|
||||
if (target == null) {
|
||||
// TODO offline messaging
|
||||
//plugin.getMessages().setMessage(targetPlayer, getLocale(playerUUID).get("makeleader.youAreNowTheOwner"));
|
||||
//plugin.getMessages().setMessage(targetPlayer, "makeleader.youAreNowTheOwner"));
|
||||
|
||||
} else {
|
||||
// Online
|
||||
@ -78,7 +78,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
// Check for zero protection range
|
||||
Island islandByOwner = getIslands().getIsland(targetUUID);
|
||||
if (islandByOwner.getProtectionRange() == 0) {
|
||||
plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
|
||||
plugin.getLogger().warning("Player " + user.getName() + "'s island had a protection range of 0. Setting to default " + range);
|
||||
islandByOwner.setProtectionRange(range);
|
||||
}
|
||||
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
|
||||
@ -90,7 +90,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
|
||||
if (spl.length > 1) {
|
||||
if (!NumberUtils.isDigits(spl[1])) {
|
||||
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
plugin.getLogger().severe("Player " + user.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
|
||||
|
||||
} else {
|
||||
hasARangePerm = true;
|
||||
@ -110,11 +110,11 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
|
||||
// Range can go up or down
|
||||
if (range != islandByOwner.getProtectionRange()) {
|
||||
player.sendMessage(getLocale(targetUUID).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
|
||||
target.sendMessage(getLocale(targetUUID).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
|
||||
user.sendMessage("admin.SetRangeUpdated", "[number]", String.valueOf(range));
|
||||
target.sendMessage("admin.SetRangeUpdated", "[number]", String.valueOf(range));
|
||||
plugin.getLogger().info(
|
||||
"Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to "
|
||||
+ range + " for " + player.getName() + " due to permission.");
|
||||
+ range + " for " + user.getName() + " due to permission.");
|
||||
}
|
||||
islandByOwner.setProtectionRange(range);
|
||||
}
|
||||
@ -124,9 +124,9 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
Set<String> result = new HashSet<>();
|
||||
for (UUID member : plugin.getIslands().getMembers(playerUUID)) {
|
||||
for (UUID member : plugin.getIslands().getMembers(user.getUniqueId())) {
|
||||
result.add(plugin.getServer().getOfflinePlayer(member).getName());
|
||||
}
|
||||
return result;
|
||||
|
@ -4,9 +4,8 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent;
|
||||
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -18,15 +17,14 @@ public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String[] args) {
|
||||
if (!isPlayer(sender)) {
|
||||
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
|
||||
public boolean execute(User user, String[] args) {
|
||||
if (!isPlayer(user)) {
|
||||
user.sendMessage("general.errors.use-in-game");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (!player.hasPermission(Settings.PERMPREFIX + "team")) {
|
||||
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
|
||||
UUID playerUUID = user.getUniqueId();
|
||||
if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
|
||||
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
|
||||
return true;
|
||||
}
|
||||
// Can only use if you have an invite out there
|
||||
@ -44,20 +42,20 @@ public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return true;
|
||||
if (inviteList.inverse().containsKey(playerUUID)) {
|
||||
Player invitee = plugin.getServer().getPlayer(inviteList.inverse().get(playerUUID));
|
||||
User invitee = User.getInstance(inviteList.inverse().get(playerUUID));
|
||||
if (invitee != null) {
|
||||
inviteList.inverse().remove(playerUUID);
|
||||
invitee.sendMessage(ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName()));
|
||||
player.sendMessage(ChatColor.GREEN + getLocale(sender).get("general.success"));
|
||||
invitee.sendMessage(ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", user.getName()));
|
||||
user.sendMessage(ChatColor.GREEN + "general.success");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage(ChatColor.YELLOW + getLocale(sender).get("help.island.invite"));
|
||||
user.sendMessage(ChatColor.YELLOW + "help.island.invite");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> tabComplete(CommandSender sender, String[] args) {
|
||||
public Set<String> tabComplete(User user, String[] args) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
@ -612,4 +613,6 @@ public class PlayersManager{
|
||||
plugin.getLogger().info("DEBUG: " + playerUUID + " is not in the cache to save");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import org.bukkit.material.TrapDoor;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.BSBDatabase;
|
||||
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
|
||||
@ -966,4 +967,6 @@ public class IslandsManager {
|
||||
save(false);
|
||||
islandCache.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -121,7 +122,7 @@ public class NewIsland {
|
||||
plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
|
||||
|
||||
// Fire event
|
||||
IslandEvent event = IslandEvent.builder()
|
||||
IslandBaseEvent event = IslandEvent.builder()
|
||||
.involvedPlayer(player.getUniqueId())
|
||||
.reason(reason)
|
||||
.island(island)
|
||||
|
@ -13,7 +13,10 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandLockEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.IslandUnlockEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.util.Util;
|
||||
@ -657,7 +660,7 @@ public class Island extends DataObject {
|
||||
public void setLocked(boolean locked){
|
||||
if(locked){
|
||||
// Lock the island
|
||||
IslandEvent event = IslandEvent.builder().island(this).reason(Reason.LOCK).build();
|
||||
IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.LOCK).build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(!event.isCancelled()){
|
||||
@ -665,7 +668,7 @@ public class Island extends DataObject {
|
||||
}
|
||||
} else {
|
||||
// Unlock the island
|
||||
IslandEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build();
|
||||
IslandBaseEvent event = IslandEvent.builder().island(this).reason(Reason.UNLOCK).build();
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(!event.isCancelled()){
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.database.managers.PlayersManager;
|
||||
import us.tastybento.bskyblock.database.objects.Island;
|
||||
@ -38,6 +39,7 @@ public class JoinLeaveListener implements Listener {
|
||||
if (playerUUID == null) {
|
||||
return;
|
||||
}
|
||||
User.getInstance(player);
|
||||
if (plugin.getPlayers().isKnown(playerUUID)) {
|
||||
if (DEBUG)
|
||||
plugin.getLogger().info("DEBUG: known player");
|
||||
@ -87,5 +89,6 @@ public class JoinLeaveListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
players.removeOnlinePlayer(event.getPlayer().getUniqueId());
|
||||
User.removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ import org.bukkit.util.BlockIterator;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -381,7 +382,7 @@ public class IslandGuard implements Listener {
|
||||
}
|
||||
}
|
||||
// Fire entry event
|
||||
final IslandEvent event = IslandEvent.builder()
|
||||
final IslandBaseEvent event = IslandEvent.builder()
|
||||
.island(islandTo)
|
||||
.reason(Reason.ENTER)
|
||||
.involvedPlayer(e.getPlayer().getUniqueId())
|
||||
@ -401,7 +402,7 @@ public class IslandGuard implements Listener {
|
||||
}
|
||||
}
|
||||
// Fire exit event
|
||||
final IslandEvent event = IslandEvent.builder()
|
||||
final IslandBaseEvent event = IslandEvent.builder()
|
||||
.island(islandTo)
|
||||
.reason(Reason.EXIT)
|
||||
.involvedPlayer(e.getPlayer().getUniqueId())
|
||||
@ -430,7 +431,7 @@ public class IslandGuard implements Listener {
|
||||
}
|
||||
}
|
||||
// Fire exit event
|
||||
final IslandEvent event = IslandEvent.builder()
|
||||
final IslandBaseEvent event = IslandEvent.builder()
|
||||
.island(islandTo)
|
||||
.reason(Reason.EXIT)
|
||||
.involvedPlayer(e.getPlayer().getUniqueId())
|
||||
@ -438,7 +439,7 @@ public class IslandGuard implements Listener {
|
||||
.build();
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
// Fire entry event
|
||||
final IslandEvent event2 = IslandEvent.builder()
|
||||
final IslandBaseEvent event2 = IslandEvent.builder()
|
||||
.island(islandTo)
|
||||
.reason(Reason.ENTER)
|
||||
.involvedPlayer(e.getPlayer().getUniqueId())
|
||||
|
@ -3,6 +3,7 @@ package us.tastybento.bskyblock.util;
|
||||
import org.bukkit.World;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent;
|
||||
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
@ -27,7 +28,7 @@ public class DeleteIslandChunks {
|
||||
public DeleteIslandChunks(final BSkyBlock plugin, final Island island) {
|
||||
//plugin.getLogger().info("DEBUG: deleting the island");
|
||||
// Fire event
|
||||
IslandEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
||||
IslandBaseEvent event = IslandEvent.builder().island(island).reason(Reason.DELETE).build();
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
@ -51,7 +52,7 @@ public class DeleteIslandChunks {
|
||||
}
|
||||
}
|
||||
// Fire event
|
||||
IslandEvent event1 = IslandEvent.builder().island(island).reason(Reason.DELETED).build();
|
||||
IslandBaseEvent event1 = IslandEvent.builder().island(island).reason(Reason.DELETED).build();
|
||||
plugin.getServer().getPluginManager().callEvent(event1);
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import us.tastybento.bskyblock.BSkyBlock;
|
||||
import us.tastybento.bskyblock.api.commands.User;
|
||||
import us.tastybento.bskyblock.config.Settings;
|
||||
import us.tastybento.bskyblock.generators.IslandWorld;
|
||||
import us.tastybento.bskyblock.util.nms.NMSAbstraction;
|
||||
@ -277,15 +278,15 @@ public class Util {
|
||||
|
||||
/**
|
||||
* Return a list of online players this player can see, i.e. are not invisible
|
||||
* @param player - if null, all player names on the server are shown
|
||||
* @param user - if null, all player names on the server are shown
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getOnlinePlayerList(Player player) {
|
||||
public static List<String> getOnlinePlayerList(User user) {
|
||||
final List<String> returned = new ArrayList<>();
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
if (player == null) {
|
||||
if (user == null) {
|
||||
returned.add(p.getName());
|
||||
} else if (player.canSee(p)) {
|
||||
} else if (user.getPlayer().canSee(p)) {
|
||||
returned.add(p.getName());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user