Add support for IslandTrust and IslandUnTrust.
This commit is contained in:
parent
72daaca943
commit
88c3ee39ec
|
|
@ -11,8 +11,7 @@ import com.alttd.cometskyblock.island.IslandData;
|
|||
import com.alttd.cometskyblock.island.oregenerator.GeneratorHandler;
|
||||
import com.alttd.cometskyblock.island.oregenerator.GeneratorLoader;
|
||||
import com.alttd.cometskyblock.listeners.BedListener;
|
||||
import com.alttd.cometskyblock.listeners.CobbestoneGeneratorListener;
|
||||
import com.alttd.cometskyblock.listeners.PlayerJoinListener;
|
||||
import com.alttd.cometskyblock.listeners.CobbestoneGeneratorListener;;
|
||||
import com.alttd.cometskyblock.listeners.PlayerListener;
|
||||
import com.alttd.cometskyblock.managers.IslandManager;
|
||||
import com.alttd.cometskyblock.worldgenerator.MasterWorldGenerator;
|
||||
|
|
@ -106,7 +105,6 @@ public class CometSkyBlockPlugin extends JavaPlugin implements CometSkyBlockAPI
|
|||
|
||||
public void loadEventListeners() {
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
pm.registerEvents(new PlayerJoinListener(this), this);
|
||||
pm.registerEvents(new BedListener(this), this);
|
||||
pm.registerEvents(new CobbestoneGeneratorListener(this), this);
|
||||
pm.registerEvents(new GUIListener(this), this);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ public class IslandCommand extends PlayerSubCommand {
|
|||
registerSubCommand(new IslandKick(plugin)); // TODO -- Add IslandKickCommand
|
||||
registerSubCommand(new IslandSetOwner(plugin));
|
||||
registerSubCommand(new IslandVisit(plugin));
|
||||
registerSubCommand(new IslandTrust(plugin));
|
||||
registerSubCommand(new IslandUnTrust(plugin));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package com.alttd.cometskyblock.commands.island;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import com.alttd.cometskyblock.request.InviteRequest;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IslandTrust extends PlayerSubCommand {
|
||||
|
||||
public IslandTrust(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "trust");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Trust trust = plugin.messagesConfiguration().get().commands().island().trust();
|
||||
if (islandPlayer.islandId() == 0) {
|
||||
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().noIsland());
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().commandUsage());
|
||||
return true;
|
||||
}
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (player == target) {
|
||||
player.sendRichMessage(trust.trustSelf());
|
||||
return true;
|
||||
}
|
||||
if (target == null) {
|
||||
player.sendRichMessage(trust.targetOffline());
|
||||
return true;
|
||||
}
|
||||
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||
UUID uuid = target.getUniqueId();
|
||||
if (island.members().contains(uuid)) {
|
||||
player.sendRichMessage(trust.targetIsMember());
|
||||
return true;
|
||||
}
|
||||
if (island.trustList().contains(uuid)) {
|
||||
player.sendRichMessage(trust.targetIsTrusted());
|
||||
return true;
|
||||
}
|
||||
|
||||
island.trust(uuid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.alttd.cometskyblock.commands.island;
|
||||
|
||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.commands.PlayerSubCommand;
|
||||
import com.alttd.cometskyblock.configuration.MessageConfiguration;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class IslandUnTrust extends PlayerSubCommand {
|
||||
|
||||
public IslandUnTrust(CometSkyBlockPlugin plugin) {
|
||||
super(plugin, "untrust");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(Player player, IslandPlayer islandPlayer, String[] args) {
|
||||
MessageConfiguration.Commands.Island.Trust trust = plugin.messagesConfiguration().get().commands().island().trust();
|
||||
if (islandPlayer.islandId() == 0) {
|
||||
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().noIsland());
|
||||
return true;
|
||||
}
|
||||
if (args.length < 1) {
|
||||
player.sendRichMessage(plugin.messagesConfiguration().get().commands().island().commandUsage());
|
||||
return true;
|
||||
}
|
||||
OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
|
||||
Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||
UUID uuid = target.getUniqueId();
|
||||
if (!island.trustList().contains(uuid)) {
|
||||
player.sendRichMessage(trust.targetIsNotTrusted());
|
||||
return true;
|
||||
}
|
||||
|
||||
island.untrust(uuid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -149,6 +149,16 @@ public class MessageConfiguration implements Configuration {
|
|||
String targetNotAMember = "<red><target> must be a member of your island.";
|
||||
}
|
||||
|
||||
Trust trust = new Trust();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Trust {
|
||||
String trustSelf = "<red>You can not trust yourself to this island.";
|
||||
String targetOffline = "<red><target> not found, is the player online?";
|
||||
String targetIsMember = "<red><target> is already a member on this island.";
|
||||
String targetIsTrusted = "<red><target> is already trusted on this island.";
|
||||
String targetIsNotTrusted = "<red><target> is not trusted on this island.";
|
||||
}
|
||||
|
||||
Visit visit = new Visit();
|
||||
@ConfigSerializable @Getter
|
||||
public static class Visit {
|
||||
|
|
|
|||
|
|
@ -163,8 +163,8 @@ public class Island extends YamlConfiguration {
|
|||
return s == null || s.isEmpty() ? NILL_UUID : UUID.fromString(s);
|
||||
}
|
||||
|
||||
public boolean canBuild(UUID uuid) {
|
||||
return owner().equals(uuid) || members().contains(uuid);
|
||||
public boolean canInteract(UUID uuid) {
|
||||
return owner().equals(uuid) || members().contains(uuid) || trustList().contains(uuid);
|
||||
}
|
||||
|
||||
public void addMember(UUID uuid) {
|
||||
|
|
@ -269,4 +269,30 @@ public class Island extends YamlConfiguration {
|
|||
}
|
||||
return contains("generator-level." + generatorTier.toString().toLowerCase(), true);
|
||||
}
|
||||
|
||||
public List<UUID> trustList() {
|
||||
List<String> trustList = getStringList("island.trust-list");
|
||||
return trustList.stream()
|
||||
.map(this::stringToUUID)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void trustList(List<UUID> trusList) {
|
||||
set("island.trust-list", trusList.stream()
|
||||
.map(uuid -> uuid == null ? "null" : uuid.toString())
|
||||
.collect(Collectors.toList()));
|
||||
save();
|
||||
}
|
||||
|
||||
public void trust(UUID uuid) {
|
||||
List<UUID> list = trustList();
|
||||
list.add(uuid);
|
||||
trustList(list);
|
||||
}
|
||||
|
||||
public void untrust(UUID uuid) {
|
||||
List<UUID> list = trustList();
|
||||
list.remove(uuid);
|
||||
trustList(list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user