Implemented User class

And also made use of it in commands
This commit is contained in:
Florian CUNY 2017-12-17 10:26:25 +01:00 committed by GitHub
parent 90f88b4425
commit cd40405c30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 569 additions and 339 deletions

View File

@ -352,7 +352,7 @@ invite:
nameHasUninvitedYou: "[name] has removed the invite to join their island!" nameHasUninvitedYou: "[name] has removed the invite to join their island!"
onlyIslandOwnerCanInvite: "Only the leader can invite!" onlyIslandOwnerCanInvite: "Only the leader can invite!"
removingInvite: "Removing your previous 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!" warningYouWillLoseIsland: "WARNING: You will lose your current island if you accept!"
youCanInvite: "You can invite [number] more players." youCanInvite: "You can invite [number] more players."
youCannotInvite: "You can't invite any more players." youCannotInvite: "You can't invite any more players."
@ -602,9 +602,8 @@ sign-acidisland:
line4: "Beware!" line4: "Beware!"
targetInPVPArea: "Target is in a no-PVP area!" targetInPVPArea: "Target is in a no-PVP area!"
team: team:
color: "&b" leader: "&a[name] - Leader"
leader-color: "&a" member: "&b[name]"
leader: " - Leader"
listingMembers: "Listing island members" listingMembers: "Listing island members"
teamchat: teamchat:
helpChat: "turn on/off team chat" helpChat: "turn on/off team chat"

View File

@ -31,8 +31,8 @@ public abstract class CommandArgument {
public CommandArgument() {} public CommandArgument() {}
public abstract boolean execute(CommandSender sender, String[] args); public abstract boolean execute(User user, String[] args);
public abstract Set<String> tabComplete(CommandSender sender, String[] args); public abstract Set<String> tabComplete(User user, String[] args);
public String getLabel() { public String getLabel() {
return label; 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 // 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 * @return true if sender is a player
*/ */
protected boolean isPlayer(CommandSender sender) { protected boolean isPlayer(User user) {
return (sender instanceof Player); return (user.getPlayer() instanceof Player);
} }
/** /**
@ -89,19 +89,19 @@ public abstract class CommandArgument {
} }
/** /**
* @param player * @param user
* @return UUID of player's team leader * @return UUID of player's team leader
*/ */
protected UUID getTeamLeader(Player player) { protected UUID getTeamLeader(User user) {
return plugin.getIslands().getTeamLeader(player.getUniqueId()); return plugin.getIslands().getTeamLeader(user.getUniqueId());
} }
/** /**
* @param player * @param user
* @return set of UUIDs of all team members * @return set of UUIDs of all team members
*/ */
protected Set<UUID> getMembers(Player player) { protected Set<UUID> getMembers(User user) {
return plugin.getIslands().getMembers(player.getUniqueId()); return plugin.getIslands().getMembers(user.getUniqueId());
} }
/** /**

View File

@ -76,7 +76,7 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
if (subCommand != null) { // check if this subcommand exists if (subCommand != null) { // check if this subcommand exists
if (!subCommand.hasSubCommmands()) { // if it has not any subcommands 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 // else continue the loop
// TODO: adapt this part to make it works with arguments that are not subcommands // TODO: adapt this part to make it works with arguments that are not subcommands

View 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);
}
}

View File

@ -2,6 +2,7 @@ package us.tastybento.bskyblock.api.events;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -18,12 +19,30 @@ public class IslandBaseEvent extends Event implements Cancellable{
private boolean cancelled; private boolean cancelled;
private final Island island; 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 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.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 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 @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;

View File

@ -13,7 +13,8 @@ import us.tastybento.bskyblock.database.objects.Island;
* @author tastybento * @author tastybento
* @since 1.0 * @since 1.0
*/ */
public class IslandEvent extends IslandBaseEvent { public class IslandEvent {
public enum Reason { public enum Reason {
CREATE, CREATE,
CREATED, CREATED,
@ -27,38 +28,78 @@ public class IslandEvent extends IslandBaseEvent {
UNLOCK, UNLOCK,
UNKNOWN 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() { public static IslandEventBuilder builder() {
return new IslandEventBuilder(); 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 { public static class IslandEventBuilder {
// Here field are NOT final. They are just used for the building. // Here field are NOT final. They are just used for the building.
private Island island; private Island island;
@ -66,12 +107,12 @@ public class IslandEvent extends IslandBaseEvent {
private Reason reason = Reason.UNKNOWN; private Reason reason = Reason.UNKNOWN;
private boolean admin; private boolean admin;
private Location location; private Location location;
public IslandEventBuilder island(Island island) { public IslandEventBuilder island(Island island) {
this.island = island; this.island = island;
return this; return this;
} }
/** /**
* True if this is an admin driven event * True if this is an admin driven event
* @param admin * @param admin
@ -90,7 +131,7 @@ public class IslandEvent extends IslandBaseEvent {
this.reason = reason; this.reason = reason;
return this; return this;
} }
/** /**
* @param player involved in the event * @param player involved in the event
* @return * @return
@ -99,41 +140,38 @@ public class IslandEvent extends IslandBaseEvent {
this.player = player; this.player = player;
return this; return this;
} }
public IslandEvent build() {
return new IslandEvent(island, player, admin, reason, location);
}
public IslandEventBuilder location(Location location) { public IslandEventBuilder location(Location center) {
this.location = location; this.location = center;
return this; 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;
}
} }

View File

@ -2,11 +2,8 @@ package us.tastybento.bskyblock.commands.admin;
import java.util.Set; 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.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
public class AdminVersionCommand extends CommandArgument { public class AdminVersionCommand extends CommandArgument {
@ -15,14 +12,13 @@ public class AdminVersionCommand extends CommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
sender.sendMessage(Bukkit.getBukkitVersion()); return false;
sender.sendMessage("BSB " + BSkyBlock.getPlugin().getDescription().getVersion());
return true;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -2,10 +2,9 @@ package us.tastybento.bskyblock.commands.island;
import java.util.Set; import java.util.Set;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.CommandArgument; import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
public class IslandAboutCommand extends CommandArgument { public class IslandAboutCommand extends CommandArgument {
@ -14,41 +13,41 @@ public class IslandAboutCommand extends CommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
sender.sendMessage("About " + BSkyBlock.getPlugin().getDescription().getName() + " v" + BSkyBlock.getPlugin().getDescription().getVersion() + ":"); user.sendMessage("About " + BSkyBlock.getPlugin().getDescription().getName() + " v" + BSkyBlock.getPlugin().getDescription().getVersion() + ":");
sender.sendMessage("Copyright (c) 2017 - 2018 tastybento, Poslovitch"); user.sendMessage("Copyright (c) 2017 - 2018 tastybento, Poslovitch");
sender.sendMessage("All rights reserved."); user.sendMessage("All rights reserved.");
sender.sendMessage(""); user.sendMessage("");
sender.sendMessage("Redistribution and use in source and binary forms, with or without"); user.sendMessage("Redistribution and use in source and binary forms, with or without");
sender.sendMessage("modification, are permitted provided that the following conditions are met:"); user.sendMessage("modification, are permitted provided that the following conditions are met:");
sender.sendMessage(" * Redistributions of source code must retain the above copyright notice,"); user.sendMessage(" * Redistributions of source code must retain the above copyright notice,");
sender.sendMessage(" this list of conditions and the following disclaimer."); user.sendMessage(" this list of conditions and the following disclaimer.");
sender.sendMessage(" * Redistributions in binary form must reproduce the above copyright"); user.sendMessage(" * Redistributions in binary form must reproduce the above copyright");
sender.sendMessage(" notice, this list of conditions and the following disclaimer in the"); user.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(" documentation and/or other materials provided with the distribution.");
sender.sendMessage(" * Neither the name of the BSkyBlock team nor the names of its"); user.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"); user.sendMessage(" contributors may be used to endorse or promote products derived from");
sender.sendMessage(" this software without specific prior written permission."); user.sendMessage(" this software without specific prior written permission.");
sender.sendMessage("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\""); user.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"); user.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"); user.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"); user.sendMessage("ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE");
sender.sendMessage("LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR"); user.sendMessage("LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR");
sender.sendMessage("CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF"); user.sendMessage("CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF");
sender.sendMessage("SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"); user.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"); user.sendMessage("INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN");
sender.sendMessage("CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)"); user.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"); user.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("POSSIBILITY OF SUCH DAMAGE. ");
return false; return false;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User sender, String[] args) {
return null; return null;
} }
} }

View File

@ -7,10 +7,10 @@ import java.io.IOException;
import java.util.Set; import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument; 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.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.create")) { 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())) { 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)) { if (inTeam(player)) {
return false; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -7,10 +7,10 @@ import java.util.Set;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument; import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.home")) { 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; return true;
} }
if (!getIslands().hasIsland(player.getUniqueId())) { 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; return true;
} }
if (args.length == 1 && NumberUtils.isDigits(args[0])) { 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -5,10 +5,10 @@ import java.util.Set;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument; 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.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland; import us.tastybento.bskyblock.database.managers.island.NewIsland;
@ -23,25 +23,25 @@ public class IslandResetCommand extends CommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.reset")) { if (!player.hasPermission(Settings.PERMPREFIX + "island.reset")) {
sender.sendMessage(getLocale(sender).get("general.errors.no-permission")); user.sendMessage("general.errors.no-permission");
return true; return true;
} }
if (!getIslands().hasIsland(player.getUniqueId())) { if (!getIslands().hasIsland(player.getUniqueId())) {
sender.sendMessage(getLocale(sender).get("general.errors.no-island")); user.sendMessage("general.errors.no-island");
return true; return true;
} }
if (!getIslands().isOwner(player.getUniqueId())) { if (!getIslands().isOwner(player.getUniqueId())) {
return false; return false;
} }
if (inTeam(player)) { if (inTeam(player)) {
sender.sendMessage(getLocale(sender).get("island.reset.MustRemovePlayers")); user.sendMessage("island.reset.MustRemovePlayers");
return true; return true;
} }
@ -65,14 +65,14 @@ public class IslandResetCommand extends CommandArgument {
.build(); .build();
} catch (IOException e) { } catch (IOException e) {
plugin.getLogger().severe("Could not create island for player."); 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(); e.printStackTrace();
} }
return true; return true;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -7,10 +7,10 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument; import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; Player player = (Player)user;
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) { 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; return true;
} }
if (!getIslands().hasIsland(playerUUID)) { 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; return true;
} }
if (!getIslands().isOwner(playerUUID)) { 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; return true;
} }
// Explain command // Explain command
@ -61,11 +61,11 @@ public class IslandResetnameCommand extends CommandArgument {
// Check if the name isn't too short or too long // Check if the name isn't too short or too long
if (name.length() < Settings.nameMinLength) { 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; return true;
} }
if (name.length() > Settings.nameMaxLength) { 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; return true;
} }
@ -74,7 +74,7 @@ public class IslandResetnameCommand extends CommandArgument {
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name)); getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
else getIslands().getIsland(playerUUID).setName(name); else getIslands().getIsland(playerUUID).setName(name);
sender.sendMessage(getLocale(sender).get("general.success")); user.sendMessage("general.success");
return true; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -4,10 +4,9 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; 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.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -18,56 +17,55 @@ public class IslandSethomeCommand extends CommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage(ChatColor.RED + "general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; UUID playerUUID = user.getUniqueId();
UUID playerUUID = player.getUniqueId(); if (!user.hasPermission(Settings.PERMPREFIX + "island.sethome")) {
if (!player.hasPermission(Settings.PERMPREFIX + "island.sethome")) { user.sendMessage(ChatColor.RED + "general.errors.no-permission");
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true; return true;
} }
// Check island // Check island
if (plugin.getIslands().getIsland(player.getUniqueId()) == null) { if (plugin.getIslands().getIsland(user.getUniqueId()) == null) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-island")); user.sendMessage(ChatColor.RED + "general.errors.no-island");
return true; return true;
} }
if (!plugin.getIslands().playerIsOnIsland(player)) { if (!plugin.getIslands().playerIsOnIsland(user.getPlayer())) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NotOnIsland")); user.sendMessage(ChatColor.RED + "sethome.error.NotOnIsland");
return true; return true;
} }
if (args.length == 0) { if (args.length == 0) {
// island sethome // island sethome
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation()); plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation());
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet")); user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
} else if (args.length == 1) { } else if (args.length == 1) {
// Dynamic home sizes with permissions // 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) { if (maxHomes > 1) {
// Check the number given is a number // Check the number given is a number
int number = 0; int number = 0;
try { try {
number = Integer.valueOf(args[0]); number = Integer.valueOf(args[0]);
if (number < 1 || number > maxHomes) { 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 { } else {
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation(), number); plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation(), number);
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet")); user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
} }
} catch (Exception e) { } 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 { } else {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-permission")); user.sendMessage(ChatColor.RED + "general.errors.no-permission");
} }
} }
return true; return true;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -7,10 +7,10 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument; import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; Player player = (Player)user;
UUID playerUUID = player.getUniqueId(); UUID playerUUID = player.getUniqueId();
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) { 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; return true;
} }
if (!getIslands().hasIsland(playerUUID)) { 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; return true;
} }
if (!getIslands().isOwner(playerUUID)) { 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; return true;
} }
// Resets the island name // Resets the island name
getIslands().getIsland(playerUUID).setName(null); getIslands().getIsland(playerUUID).setName(null);
sender.sendMessage(getLocale(sender).get("general.success")); user.sendMessage("general.success");
return true; 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[]) * @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/ */
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

View File

@ -7,13 +7,13 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.google.common.collect.BiMap; import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap; import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CommandArgument; import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
public abstract class AbstractIslandTeamCommandArgument extends CommandArgument { public abstract class AbstractIslandTeamCommandArgument extends CommandArgument {
@ -26,23 +26,19 @@ public abstract class AbstractIslandTeamCommandArgument extends CommandArgument
protected Set<UUID> kickingPlayers = new HashSet<>(); protected Set<UUID> kickingPlayers = new HashSet<>();
// TODO: It would be good if these could be auto-provided // TODO: It would be good if these could be auto-provided
protected CommandSender sender; protected User user;
protected Player player;
protected UUID playerUUID;
public AbstractIslandTeamCommandArgument(String label, String... aliases) { public AbstractIslandTeamCommandArgument(String label, String... aliases) {
super(label,aliases); super(label,aliases);
} }
protected boolean checkTeamPerm() { protected boolean checkTeamPerm() {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return false; return false;
} }
player = (Player)sender; if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
playerUUID = player.getUniqueId(); user.sendMessage(ChatColor.RED + "general.errors.no-permission");
if (!player.hasPermission(Settings.PERMPREFIX + "team")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return false; return false;
} }
return true; return true;

View File

@ -6,8 +6,8 @@ import java.util.UUID;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -20,25 +20,26 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// Check team perm and get variables set // Check team perm and get variables set
if (!checkTeamPerm()) return true; if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
if(!inviteList.containsKey(playerUUID)) if(!inviteList.containsKey(playerUUID))
return true; return true;
// Check if player has been invited // Check if player has been invited
if (!inviteList.containsKey(playerUUID)) { if (!inviteList.containsKey(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.NoOneInvitedYou")); user.sendMessage(ChatColor.RED + "invite.error.NoOneInvitedYou");
return true; return true;
} }
// Check if player is already in a team // Check if player is already in a team
if (getPlayers().inTeam(playerUUID)) { if (getPlayers().inTeam(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouAreAlreadyOnATeam")); user.sendMessage(ChatColor.RED + "invite.error.YouAreAlreadyOnATeam");
return true; return true;
} }
// Get the team leader // Get the team leader
UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID); UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID);
if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) { if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.InvalidInvite")); user.sendMessage(ChatColor.RED + "invite.error.InvalidInvite");
inviteList.remove(playerUUID); inviteList.remove(playerUUID);
return true; return true;
} }
@ -58,38 +59,37 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
plugin.getLogger().info("DEBUG: Removing player from invite list"); plugin.getLogger().info("DEBUG: Removing player from invite list");
inviteList.remove(playerUUID); inviteList.remove(playerUUID);
// Put player into Spectator mode // 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 // Get the player's island - may be null if the player has no island
Island island = getIslands().getIsland(playerUUID); Island island = getIslands().getIsland(playerUUID);
// Get the team's island // Get the team's island
Island teamIsland = getIslands().getIsland(prospectiveTeamLeaderUUID); Island teamIsland = getIslands().getIsland(prospectiveTeamLeaderUUID);
// Clear the player's inventory // Clear the player's inventory
player.getInventory().clear(); user.getInventory().clear();
// Move player to team's island // Move player to team's island
Location newHome = getIslands().getSafeHomeLocation(prospectiveTeamLeaderUUID, 1); Location newHome = getIslands().getSafeHomeLocation(prospectiveTeamLeaderUUID, 1);
player.teleport(newHome); user.teleport(newHome);
// Remove player as owner of the old island // Remove player as owner of the old island
getIslands().removePlayer(playerUUID); getIslands().removePlayer(playerUUID);
// Add the player as a team member of the new island // Add the player as a team member of the new island
getIslands().setJoinTeam(teamIsland, playerUUID); getIslands().setJoinTeam(teamIsland, playerUUID);
// Set the player's home // Set the player's home
getPlayers().setHomeLocation(playerUUID, player.getLocation()); getPlayers().setHomeLocation(playerUUID, user.getLocation());
// Delete the old island // Delete the old island
getIslands().deleteIsland(island, true); getIslands().deleteIsland(island, true);
// Set the cooldown // Set the cooldown
setResetWaitTime(player); setResetWaitTime(user.getPlayer());
// Reset deaths // Reset deaths
if (Settings.teamJoinDeathReset) { if (Settings.teamJoinDeathReset) {
getPlayers().setDeaths(playerUUID, 0); getPlayers().setDeaths(playerUUID, 0);
} }
// Put player back into normal mode // 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)); user.sendMessage(ChatColor.GREEN + "invite.youHaveJoinedAnIsland", "[label]", Settings.ISLANDCOMMAND);
User inviter = User.getInstance(inviteList.get(playerUUID));
if (plugin.getServer().getPlayer(inviteList.get(playerUUID)) != null) { if (inviter != null) {
plugin.getServer().getPlayer(inviteList.get(playerUUID)).sendMessage( inviter.sendMessage(ChatColor.GREEN + "invite.hasJoinedYourIsland", "[name]", user.getName());
ChatColor.GREEN + getLocale(sender).get("invite.hasJoinedYourIsland").replace("[name]", player.getName()));
} }
getIslands().save(false); getIslands().save(false);
if (DEBUG) if (DEBUG)
@ -99,7 +99,7 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
return null; return null;
} }
} }

View File

@ -1,11 +1,11 @@
package us.tastybento.bskyblock.commands.island.teams; package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
@ -16,9 +16,10 @@ public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// Check team perm and get variables set // Check team perm and get variables set
if (!checkTeamPerm()) return true; if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Reject /island reject // Reject /island reject
if (inviteList.containsKey(playerUUID)) { if (inviteList.containsKey(playerUUID)) {
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
@ -32,24 +33,25 @@ public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
// Remove this player from the global invite list // Remove this player from the global invite list
inviteList.remove(player.getUniqueId()); inviteList.remove(user.getUniqueId());
player.sendMessage(ChatColor.GREEN + getLocale(playerUUID).get("reject.youHaveRejectedInvitation")); user.sendMessage(ChatColor.GREEN + "reject.youHaveRejectedInvitation");
// If the leader is online tell them directly // If the leader is online tell them directly
// about the rejection // about the rejection
if (Bukkit.getPlayer(inviteList.get(playerUUID)) != null) { User inviter = User.getInstance(inviteList.get(playerUUID));
Bukkit.getPlayer(inviteList.get(playerUUID)).sendMessage( if (inviter != null) {
ChatColor.RED + getLocale(playerUUID).get("reject.nameHasRejectedInvite").replace("[name]", player.getName())); inviter.sendMessage(
ChatColor.RED + "reject.nameHasRejectedInvite", "[name]", user.getName());
} }
} else { } else {
// Someone typed /island reject and had not been invited // 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; return true;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
return null; return null;
} }
} }

View File

@ -2,24 +2,25 @@ package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set; import java.util.Set;
import org.bukkit.command.CommandSender; import us.tastybento.bskyblock.api.commands.User;
public class IslandLeaveCommand extends AbstractIslandTeamCommandArgument { public class IslandLeaveCommand extends AbstractIslandTeamCommandArgument {
public IslandLeaveCommand(String label, String[] aliases) { public IslandLeaveCommand() {
super(label, aliases); super("leave");
// TODO Auto-generated constructor stub
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return false; return false;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }
} }

View File

@ -5,9 +5,9 @@ import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionAttachmentInfo; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -22,10 +22,10 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// Check team perm and get variables set // Check team perm and get variables set
if (!checkTeamPerm()) return true; if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: executing team command for " + playerUUID); plugin.getLogger().info("DEBUG: executing team command for " + playerUUID);
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
@ -37,11 +37,11 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
.build(); .build();
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
UUID teamLeaderUUID = getTeamLeader(player); UUID teamLeaderUUID = getTeamLeader(user);
Set<UUID> teamMembers = getMembers(player); Set<UUID> teamMembers = getMembers(user);
if (teamLeaderUUID.equals(playerUUID)) { if (teamLeaderUUID.equals(playerUUID)) {
int maxSize = Settings.maxTeamSize; 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().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize; maxSize = Settings.maxTeamSize;
@ -51,7 +51,7 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1])); maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
} }
@ -63,27 +63,27 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
} }
if (teamMembers.size() < maxSize) { 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 { } 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 // Display members in the list
for (UUID m : teamMembers) { for (UUID m : teamMembers) {
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: member " + m); plugin.getLogger().info("DEBUG: member " + m);
if (teamLeaderUUID.equals(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 { } else {
sender.sendMessage(getLocale(sender).get("team.color") + getPlayers().getName(m)); user.sendMessage("team.member", "[name]", getPlayers().getName(m));
} }
} }
return true; return true;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
return null; return null;
} }
} }

View File

@ -8,10 +8,9 @@ import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -24,25 +23,25 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// Check team perm and get variables set // Check team perm and get variables set
if (!checkTeamPerm()) return true; if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Player issuing the command must have an island // Player issuing the command must have an island
if (!getPlayers().hasIsland(playerUUID)) { if (!getPlayers().hasIsland(playerUUID)) {
// If the player is in a team, they are not the leader // If the player is in a team, they are not the leader
if (getPlayers().inTeam(playerUUID)) { 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) { 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 // Invite label with no name, i.e., /island invite - tells the player who has invited them so far
if (inviteList.containsKey(playerUUID)) { if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = plugin.getServer().getOfflinePlayer(inviteList.get(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 { } else {
player.sendMessage(ChatColor.GOLD + getLocale(sender).get("help.island.invite")); user.sendMessage(ChatColor.GOLD + "help.island.invite");
} }
return true; return true;
} }
@ -50,36 +49,36 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
// Only online players can be invited // Only online players can be invited
UUID invitedPlayerUUID = getPlayers().getUUID(args[0]); UUID invitedPlayerUUID = getPlayers().getUUID(args[0]);
if (invitedPlayerUUID == null) { if (invitedPlayerUUID == null) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player")); user.sendMessage(ChatColor.RED + "general.errors.offline-player");
return true; return true;
} }
Player invitedPlayer = plugin.getServer().getPlayer(invitedPlayerUUID); User invitedPlayer = User.getInstance(invitedPlayerUUID);
if (invitedPlayer == null) { if (!invitedPlayer.isOnline()) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player")); user.sendMessage(ChatColor.RED + "general.errors.offline-player");
return true; return true;
} }
// Player cannot invite themselves // Player cannot invite themselves
if (playerUUID.equals(invitedPlayerUUID)) { if (playerUUID.equals(invitedPlayerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouCannotInviteYourself")); user.sendMessage(ChatColor.RED + "invite.error.YouCannotInviteYourself");
return true; return true;
} }
// Check if this player can be invited to this island, or // Check if this player can be invited to this island, or
// whether they are still on cooldown // whether they are still on cooldown
long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(playerUUID)); long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(playerUUID));
if (time > 0 && !player.isOp()) { if (time > 0 && !user.isOp()) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.CoolDown").replace("[time]", String.valueOf(time))); user.sendMessage(ChatColor.RED + "invite.error.CoolDown", "[time]", String.valueOf(time));
return true; return true;
} }
// Player cannot invite someone already on a team // Player cannot invite someone already on a team
if (getPlayers().inTeam(invitedPlayerUUID)) { if (getPlayers().inTeam(invitedPlayerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.ThatPlayerIsAlreadyInATeam")); user.sendMessage(ChatColor.RED + "invite.error.ThatPlayerIsAlreadyInATeam");
return true; return true;
} }
Set<UUID> teamMembers = getMembers(player); Set<UUID> teamMembers = getMembers(user);
// Check if player has space on their team // Check if player has space on their team
int maxSize = Settings.maxTeamSize; int maxSize = Settings.maxTeamSize;
// Dynamic team sizes with permissions // 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().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) { if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize; maxSize = Settings.maxTeamSize;
@ -89,7 +88,7 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1])); 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 // Players can only have one invite one at a time - interesting
if (inviteList.containsValue(playerUUID)) { if (inviteList.containsValue(playerUUID)) {
inviteList.inverse().remove(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. // Fire event so add-ons can run commands, etc.
TeamEvent event = TeamEvent.builder() TeamEvent event = TeamEvent.builder()
@ -117,27 +116,26 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
// Put the invited player (key) onto the list with inviter (value) // 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! // If someone else has invited a player, then this invite will overwrite the previous invite!
inviteList.put(invitedPlayerUUID, playerUUID); 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 // Send message to online player
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD + getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName())); invitedPlayer.sendMessage(ChatColor.GOLD + "invite.nameHasInvitedYou", "[name]", user.getName());
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD + invitedPlayer.sendMessage(ChatColor.GOLD + "invite.toAcceptOrReject", "[label]", getLabel());
"/" + getLabel() + " [accept/reject]" + " " + getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject")); if (getPlayers().hasIsland(invitedPlayer.getUniqueId())) {
if (getPlayers().hasIsland(invitedPlayerUUID)) {
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.RED + getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland")); Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.RED + getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland"));
} }
} else { } else {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull")); user.sendMessage(ChatColor.RED + "invite.error.YourIslandIsFull");
} }
} }
return false; return false;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
if (args.length == 0 || !(sender instanceof Player)) { if (args.length == 0 || !isPlayer(user)) {
// Don't show every player on the server. Require at least the first letter // Don't show every player on the server. Require at least the first letter
return null; return null;
} }
return new HashSet<>(Util.getOnlinePlayerList((Player) sender)); return new HashSet<>(Util.getOnlinePlayerList(user));
} }
} }

View File

@ -1,25 +1,6 @@
package us.tastybento.bskyblock.commands.island.teams; 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;
}
} }

View File

@ -6,10 +6,9 @@ import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -22,9 +21,10 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
// Check team perm and get variables set // Check team perm and get variables set
if (!checkTeamPerm()) return true; if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Can use if in a team // Can use if in a team
boolean inTeam = plugin.getPlayers().inTeam(playerUUID); boolean inTeam = plugin.getPlayers().inTeam(playerUUID);
UUID teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID); UUID teamLeaderUUID = plugin.getIslands().getTeamLeader(playerUUID);
@ -34,23 +34,23 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
plugin.getLogger().info("DEBUG: arg[0] = " + args[0]); plugin.getLogger().info("DEBUG: arg[0] = " + args[0]);
UUID targetUUID = getPlayers().getUUID(args[0]); UUID targetUUID = getPlayers().getUUID(args[0]);
if (targetUUID == null) { if (targetUUID == null) {
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("general.errors.unknown-player")); user.sendMessage(ChatColor.RED + "general.errors.unknown-player");
return true; return true;
} }
if (!getPlayers().inTeam(playerUUID)) { if (!getPlayers().inTeam(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorYouMustBeInTeam")); user.sendMessage(ChatColor.RED + "makeleader.errorYouMustBeInTeam");
return true; return true;
} }
if (!teamLeaderUUID.equals(playerUUID)) { if (!teamLeaderUUID.equals(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorNotYourIsland")); user.sendMessage(ChatColor.RED + "makeleader.errorNotYourIsland");
return true; return true;
} }
if (targetUUID.equals(playerUUID)) { if (targetUUID.equals(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorGeneralError")); user.sendMessage(ChatColor.RED + "makeleader.errorGeneralError");
return true; return true;
} }
if (!plugin.getIslands().getMembers(playerUUID).contains(targetUUID)) { if (!plugin.getIslands().getMembers(playerUUID).contains(targetUUID)) {
player.sendMessage(ChatColor.RED + getLocale(playerUUID).get("makeleader.errorThatPlayerIsNotInTeam")); user.sendMessage(ChatColor.RED + "makeleader.errorThatPlayerIsNotInTeam");
return true; return true;
} }
// Fire event so add-ons can run commands, etc. // Fire event so add-ons can run commands, etc.
@ -60,14 +60,14 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
// target is the new leader // target is the new leader
getIslands().getIsland(playerUUID).setOwner(targetUUID); getIslands().getIsland(playerUUID).setOwner(targetUUID);
player.sendMessage(ChatColor.GREEN user.sendMessage(ChatColor.GREEN
+ getLocale(playerUUID).get("makeleader.nameIsNowTheOwner").replace("[name]", getPlayers().getName(targetUUID))); + "makeleader.nameIsNowTheOwner", "[name]", getPlayers().getName(targetUUID));
// Check if online // Check if online
Player target = plugin.getServer().getPlayer(targetUUID); User target = User.getInstance(targetUUID);
if (target == null) { if (target == null) {
// TODO offline messaging // TODO offline messaging
//plugin.getMessages().setMessage(targetPlayer, getLocale(playerUUID).get("makeleader.youAreNowTheOwner")); //plugin.getMessages().setMessage(targetPlayer, "makeleader.youAreNowTheOwner"));
} else { } else {
// Online // Online
@ -78,7 +78,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
// Check for zero protection range // Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetUUID); Island islandByOwner = getIslands().getIsland(targetUUID);
if (islandByOwner.getProtectionRange() == 0) { 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); islandByOwner.setProtectionRange(range);
} }
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) { for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
@ -90,7 +90,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range."); String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
if (spl.length > 1) { if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[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 { } else {
hasARangePerm = true; hasARangePerm = true;
@ -110,11 +110,11 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
// Range can go up or down // Range can go up or down
if (range != islandByOwner.getProtectionRange()) { if (range != islandByOwner.getProtectionRange()) {
player.sendMessage(getLocale(targetUUID).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range))); user.sendMessage("admin.SetRangeUpdated", "[number]", String.valueOf(range));
target.sendMessage(getLocale(targetUUID).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range))); target.sendMessage("admin.SetRangeUpdated", "[number]", String.valueOf(range));
plugin.getLogger().info( plugin.getLogger().info(
"Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to " "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); islandByOwner.setProtectionRange(range);
} }
@ -124,9 +124,9 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
Set<String> result = new HashSet<>(); 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()); result.add(plugin.getServer().getOfflinePlayer(member).getName());
} }
return result; return result;

View File

@ -4,9 +4,8 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import org.bukkit.ChatColor; 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;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason; import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -18,15 +17,14 @@ public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument
} }
@Override @Override
public boolean execute(CommandSender sender, String[] args) { public boolean execute(User user, String[] args) {
if (!isPlayer(sender)) { if (!isPlayer(user)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game")); user.sendMessage("general.errors.use-in-game");
return true; return true;
} }
Player player = (Player)sender; UUID playerUUID = user.getUniqueId();
UUID playerUUID = player.getUniqueId(); if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
if (!player.hasPermission(Settings.PERMPREFIX + "team")) { user.sendMessage(ChatColor.RED + "general.errors.no-permission");
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true; return true;
} }
// Can only use if you have an invite out there // Can only use if you have an invite out there
@ -44,20 +42,20 @@ public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true; if (event.isCancelled()) return true;
if (inviteList.inverse().containsKey(playerUUID)) { 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) { if (invitee != null) {
inviteList.inverse().remove(playerUUID); inviteList.inverse().remove(playerUUID);
invitee.sendMessage(ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName())); invitee.sendMessage(ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", user.getName()));
player.sendMessage(ChatColor.GREEN + getLocale(sender).get("general.success")); user.sendMessage(ChatColor.GREEN + "general.success");
} }
} else { } else {
player.sendMessage(ChatColor.YELLOW + getLocale(sender).get("help.island.invite")); user.sendMessage(ChatColor.YELLOW + "help.island.invite");
} }
return false; return false;
} }
@Override @Override
public Set<String> tabComplete(CommandSender sender, String[] args) { public Set<String> tabComplete(User user, String[] args) {
return null; return null;
} }
} }

View File

@ -15,6 +15,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.objects.Island; 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"); plugin.getLogger().info("DEBUG: " + playerUUID + " is not in the cache to save");
} }
} }
} }

View File

@ -20,6 +20,7 @@ import org.bukkit.material.TrapDoor;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase; import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler; import us.tastybento.bskyblock.database.managers.AbstractDatabaseHandler;
@ -966,4 +967,6 @@ public class IslandsManager {
save(false); save(false);
islandCache.clear(); islandCache.clear();
} }
} }

View File

@ -7,6 +7,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock; 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;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -121,7 +122,7 @@ public class NewIsland {
plugin.getPlayers().setHomeLocation(playerUUID, next, 1); plugin.getPlayers().setHomeLocation(playerUUID, next, 1);
// Fire event // Fire event
IslandEvent event = IslandEvent.builder() IslandBaseEvent event = IslandEvent.builder()
.involvedPlayer(player.getUniqueId()) .involvedPlayer(player.getUniqueId())
.reason(reason) .reason(reason)
.island(island) .island(island)

View File

@ -13,7 +13,10 @@ import org.bukkit.World;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; 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;
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.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util; import us.tastybento.bskyblock.util.Util;
@ -657,7 +660,7 @@ public class Island extends DataObject {
public void setLocked(boolean locked){ public void setLocked(boolean locked){
if(locked){ if(locked){
// Lock the island // 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); Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()){ if(!event.isCancelled()){
@ -665,7 +668,7 @@ public class Island extends DataObject {
} }
} else { } else {
// Unlock the island // 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); Bukkit.getServer().getPluginManager().callEvent(event);
if(!event.isCancelled()){ if(!event.isCancelled()){

View File

@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.PlayersManager; import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.objects.Island; import us.tastybento.bskyblock.database.objects.Island;
@ -38,6 +39,7 @@ public class JoinLeaveListener implements Listener {
if (playerUUID == null) { if (playerUUID == null) {
return; return;
} }
User.getInstance(player);
if (plugin.getPlayers().isKnown(playerUUID)) { if (plugin.getPlayers().isKnown(playerUUID)) {
if (DEBUG) if (DEBUG)
plugin.getLogger().info("DEBUG: known player"); plugin.getLogger().info("DEBUG: known player");
@ -87,5 +89,6 @@ public class JoinLeaveListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(final PlayerQuitEvent event) { public void onPlayerQuit(final PlayerQuitEvent event) {
players.removeOnlinePlayer(event.getPlayer().getUniqueId()); players.removeOnlinePlayer(event.getPlayer().getUniqueId());
User.removePlayer(event.getPlayer());
} }
} }

View File

@ -74,6 +74,7 @@ import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import us.tastybento.bskyblock.BSkyBlock; 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;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -381,7 +382,7 @@ public class IslandGuard implements Listener {
} }
} }
// Fire entry event // Fire entry event
final IslandEvent event = IslandEvent.builder() final IslandBaseEvent event = IslandEvent.builder()
.island(islandTo) .island(islandTo)
.reason(Reason.ENTER) .reason(Reason.ENTER)
.involvedPlayer(e.getPlayer().getUniqueId()) .involvedPlayer(e.getPlayer().getUniqueId())
@ -401,7 +402,7 @@ public class IslandGuard implements Listener {
} }
} }
// Fire exit event // Fire exit event
final IslandEvent event = IslandEvent.builder() final IslandBaseEvent event = IslandEvent.builder()
.island(islandTo) .island(islandTo)
.reason(Reason.EXIT) .reason(Reason.EXIT)
.involvedPlayer(e.getPlayer().getUniqueId()) .involvedPlayer(e.getPlayer().getUniqueId())
@ -430,7 +431,7 @@ public class IslandGuard implements Listener {
} }
} }
// Fire exit event // Fire exit event
final IslandEvent event = IslandEvent.builder() final IslandBaseEvent event = IslandEvent.builder()
.island(islandTo) .island(islandTo)
.reason(Reason.EXIT) .reason(Reason.EXIT)
.involvedPlayer(e.getPlayer().getUniqueId()) .involvedPlayer(e.getPlayer().getUniqueId())
@ -438,7 +439,7 @@ public class IslandGuard implements Listener {
.build(); .build();
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
// Fire entry event // Fire entry event
final IslandEvent event2 = IslandEvent.builder() final IslandBaseEvent event2 = IslandEvent.builder()
.island(islandTo) .island(islandTo)
.reason(Reason.ENTER) .reason(Reason.ENTER)
.involvedPlayer(e.getPlayer().getUniqueId()) .involvedPlayer(e.getPlayer().getUniqueId())

View File

@ -3,6 +3,7 @@ package us.tastybento.bskyblock.util;
import org.bukkit.World; import org.bukkit.World;
import us.tastybento.bskyblock.BSkyBlock; 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;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason; import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -27,7 +28,7 @@ public class DeleteIslandChunks {
public DeleteIslandChunks(final BSkyBlock plugin, final Island island) { public DeleteIslandChunks(final BSkyBlock plugin, final Island island) {
//plugin.getLogger().info("DEBUG: deleting the island"); //plugin.getLogger().info("DEBUG: deleting the island");
// Fire event // 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); plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) if (event.isCancelled())
return; return;
@ -51,7 +52,7 @@ public class DeleteIslandChunks {
} }
} }
// Fire event // 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); plugin.getServer().getPluginManager().callEvent(event1);
} }

View File

@ -27,6 +27,7 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.generators.IslandWorld; import us.tastybento.bskyblock.generators.IslandWorld;
import us.tastybento.bskyblock.util.nms.NMSAbstraction; 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 * 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 * @return
*/ */
public static List<String> getOnlinePlayerList(Player player) { public static List<String> getOnlinePlayerList(User user) {
final List<String> returned = new ArrayList<>(); final List<String> returned = new ArrayList<>();
for (Player p : Bukkit.getServer().getOnlinePlayers()) { for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (player == null) { if (user == null) {
returned.add(p.getName()); returned.add(p.getName());
} else if (player.canSee(p)) { } else if (user.getPlayer().canSee(p)) {
returned.add(p.getName()); returned.add(p.getName());
} }
} }