mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-10 17:58:03 +01:00
Added a proxy system.
This commit is contained in:
parent
2b20e1a794
commit
2124792ae8
@ -104,6 +104,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
|
||||
new RemoveUpgradeCommand(),
|
||||
new SetBiomeCommand(),
|
||||
new SetAlwaysLoadedCommand(),
|
||||
new ProxyCommand(),
|
||||
new SetHologramCommand(),
|
||||
new SetSizeCommand(),
|
||||
new com.songoda.skyblock.command.commands.admin.SetSpawnCommand(),
|
||||
|
@ -0,0 +1,100 @@
|
||||
package com.songoda.skyblock.command.commands.admin;
|
||||
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.player.OfflinePlayer;
|
||||
import com.songoda.skyblock.utils.version.Sounds;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProxyCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
onCommand(player, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCommandByConsole(ConsoleCommandSender sender, String[] args) {
|
||||
onCommand(sender, args);
|
||||
}
|
||||
|
||||
public void onCommand(CommandSender sender, String[] args) {
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
|
||||
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
|
||||
if (args.length == 1) {
|
||||
Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);
|
||||
UUID islandOwnerUUID;
|
||||
|
||||
if (targetPlayer == null) {
|
||||
OfflinePlayer targetPlayerOffline = new OfflinePlayer(args[0]);
|
||||
islandOwnerUUID = targetPlayerOffline.getOwner();
|
||||
} else {
|
||||
islandOwnerUUID = playerDataManager.getPlayerData(targetPlayer).getOwner();
|
||||
}
|
||||
|
||||
if (islandManager.containsIsland(islandOwnerUUID)) {
|
||||
if (islandManager.isPlayerProxyingAnotherPlayer(((Player)sender).getUniqueId())) {
|
||||
messageManager.sendMessage(sender,
|
||||
configLoad.getString("Command.Island.Admin.Proxy.IsOff.Message")
|
||||
.replace("%player", targetPlayer.getName()));
|
||||
soundManager.playSound(sender, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
islandManager.removeProxyingPlayer(((Player)sender).getUniqueId());
|
||||
} else {
|
||||
messageManager.sendMessage(sender,
|
||||
configLoad.getString("Command.Island.Admin.Proxy.IsOnPlayer.Message")
|
||||
.replace("%player", targetPlayer.getName()));
|
||||
soundManager.playSound(sender, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
islandManager.addProxiedPlayer(((Player)sender).getUniqueId(), targetPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
} else if (args.length == 0){
|
||||
messageManager.sendMessage(sender,
|
||||
configLoad.getString("Command.Island.Admin.Proxy.IsOff.Message")
|
||||
.replace("%player", ""));
|
||||
soundManager.playSound(sender, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
|
||||
|
||||
islandManager.removeProxyingPlayer(((Player)sender).getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "proxy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoMessagePath() {
|
||||
return "Command.Island.Admin.Proxy.Info.Message";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAliases() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getArguments() {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
@ -579,7 +579,7 @@ public class Island {
|
||||
|
||||
public boolean hasRole(IslandRole role, UUID uuid) {
|
||||
if (role == IslandRole.Owner) {
|
||||
return getOwnerUUID().equals(uuid);
|
||||
return getOwnerUUID().equals(uuid) || skyblock.getIslandManager().isPlayerProxyingAnotherPlayer(uuid, getOwnerUUID());
|
||||
}
|
||||
|
||||
return getRole(role).contains(uuid);
|
||||
|
@ -52,6 +52,7 @@ public class IslandManager {
|
||||
private double x = 0, offset = 1200;
|
||||
|
||||
private List<IslandPosition> islandPositions = new ArrayList<>();
|
||||
private Map<UUID, UUID> islandProxies = new HashMap<>();
|
||||
private Map<UUID, Island> islandStorage = new HashMap<>();
|
||||
|
||||
public IslandManager(SkyBlock skyblock) {
|
||||
@ -983,11 +984,15 @@ public class IslandManager {
|
||||
public Island getIsland(org.bukkit.OfflinePlayer offlinePlayer) {
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
|
||||
UUID uuid = offlinePlayer.getUniqueId();
|
||||
if (islandProxies.containsKey(uuid))
|
||||
uuid = islandProxies.get(uuid);
|
||||
|
||||
// TODO: Find out how this can be fixed without this, for some reason IslandManager tries to load PlayerDataManager before it's even loaded
|
||||
if (playerDataManager == null) return null;
|
||||
|
||||
if (islandStorage.containsKey(offlinePlayer.getUniqueId())) {
|
||||
return islandStorage.get(offlinePlayer.getUniqueId());
|
||||
if (islandStorage.containsKey(uuid)) {
|
||||
return islandStorage.get(uuid);
|
||||
}
|
||||
|
||||
if (offlinePlayer.isOnline()) {
|
||||
@ -1381,6 +1386,22 @@ public class IslandManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isPlayerProxyingAnotherPlayer(UUID proxying) {
|
||||
return islandProxies.containsKey(proxying);
|
||||
}
|
||||
|
||||
public boolean isPlayerProxyingAnotherPlayer(UUID proxying, UUID proxied) {
|
||||
return islandProxies.containsKey(proxying) && islandProxies.get(proxying) == proxied;
|
||||
}
|
||||
|
||||
public void addProxiedPlayer(UUID toProxy, UUID proxied) {
|
||||
islandProxies.put(toProxy, proxied);
|
||||
}
|
||||
|
||||
public void removeProxyingPlayer(UUID toProxy) {
|
||||
islandProxies.remove(toProxy);
|
||||
}
|
||||
|
||||
public boolean isPlayerAtIsland(Island island, Player player) {
|
||||
return isLocationAtIsland(island, player.getLocation());
|
||||
}
|
||||
|
@ -231,6 +231,15 @@ Command:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eThis island will unload.'
|
||||
Info:
|
||||
Message: '&f&oKeeps an island from unloading.'
|
||||
Proxy:
|
||||
IsOn:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYou are now proxying %player.'
|
||||
IsOffPlayer:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYou are no longer proxying %player.'
|
||||
IsOff:
|
||||
Message: '&bSkyBlock &8| &aInfo&8: &eYou are no longer proxying a player.'
|
||||
Info:
|
||||
Message: '&f&oAllows you to execute island commands as another player.'
|
||||
AddUpgrade:
|
||||
Info:
|
||||
Message: '&f&oAdd an upgrade to a player''s Island.'
|
||||
|
Loading…
Reference in New Issue
Block a user