Skip to content

Commit

Permalink
* Finalized 1.3.1 additions and optimizations, ready for live usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hempfest committed Nov 17, 2021
1 parent e13a23b commit 74e5b4c
Show file tree
Hide file tree
Showing 54 changed files with 1,665 additions and 1,063 deletions.
8 changes: 7 additions & 1 deletion ClansPro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>20.1.0</version>
<version>22.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -162,6 +162,12 @@
<version>1.7.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.the-h-team</groupId>
<artifactId>labyrinth-paste</artifactId>
<version>1.7.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.the-h-team</groupId>
<artifactId>labyrinth-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import com.github.sanctum.labyrinth.library.HUID;
import com.github.sanctum.labyrinth.library.NamespacedKey;
import com.github.sanctum.labyrinth.library.StringUtils;
import com.github.sanctum.labyrinth.paste.PasteManager;
import com.github.sanctum.labyrinth.paste.type.Hastebin;
import com.github.sanctum.labyrinth.task.Schedule;
import com.github.sanctum.labyrinth.task.Task;
import com.github.sanctum.skulls.CustomHead;
Expand All @@ -63,6 +65,13 @@


/**
*
* ▄▄▄·▄▄▄ ▄▄
* ▐█ ▄█▀▄ █·▪ ██▌
* ██▀·▐▀▀▄ ▄█▀▄ ▐█·
* ▐█▪·•▐█•█▌▐█▌.▐▌.▀
* .▀ .▀ ▀ ▀█▄▀▪ ▀
*
* <pre>
* <h3>MIT License</h2>
* Copyright (c) 2021 Sanctum
Expand Down Expand Up @@ -103,6 +112,7 @@ public class ClansJavaPlugin extends JavaPlugin implements ClansAPI {
private ClanManager clanManager;
private LogoGallery gallery;
public DataManager dataManager;
private Hastebin hastebin;
private KeyedServiceManager<ClanAddon> serviceManager;

public String USER_ID = "%%__USER__%%";
Expand All @@ -112,35 +122,7 @@ public class ClansJavaPlugin extends JavaPlugin implements ClansAPI {
public void onEnable() {
initialize();

String state = LabyrinthProvider.getInstance().getContainer(STATE).get(String.class, "toString");
if (state != null) {
boolean recorded = Boolean.parseBoolean(state);
if (recorded != Bukkit.getOnlineMode()) {
if (!Clan.ACTION.getAllClanIDs().isEmpty()) {
FancyMessageChain chain = new FancyMessageChain();
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then(" [Online state change detected] "));
chain.append(msg -> msg.then("[To use this plugin again your clan data must be reset]"));
chain.append(msg -> msg.then(" [This is due to a change in unique id's for players.] "));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
for (Message m : chain) {
Bukkit.getConsoleSender().spigot().sendMessage(m.build());
}
getServer().getPluginManager().disablePlugin(this);
return;
} else {
LabyrinthProvider.getInstance().getContainer(STATE).delete("toString");
}
}
}
if (isInvalid()) return;

Configurable.registerClass(Clan.class);
Configurable.registerClass(Claim.class);
Expand Down Expand Up @@ -209,6 +191,45 @@ public void onEnable() {
}).waitReal(12);

CustomHead.Manager.newLoader(man.getRoot()).look("My_heads").complete();
ReservedLogoCarrier reserved2 = ReservedLogoCarrier.SUMMER;
getLogoGallery().load(reserved2.getId(), reserved2.get());
ReservedLogoCarrier reserved3 = ReservedLogoCarrier.HALLOWEEN;
getLogoGallery().load(reserved3.getId(), reserved3.get());
ReservedLogoCarrier reserved4 = ReservedLogoCarrier.BIG_LANDSCAPE;
getLogoGallery().load(reserved4.getId(), reserved4.get());
}

private boolean isInvalid() {
String state = LabyrinthProvider.getInstance().getContainer(STATE).get(String.class, "toString");
if (state != null) {
boolean recorded = Boolean.parseBoolean(state);
if (recorded != Bukkit.getOnlineMode()) {
if (!Clan.ACTION.getAllClanIDs().isEmpty()) {
FancyMessageChain chain = new FancyMessageChain();
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then(" [Online state change detected] "));
chain.append(msg -> msg.then("[To use this plugin again your clan data must be reset]"));
chain.append(msg -> msg.then(" [This is due to a change in unique id's for players.] "));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("======================================================="));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
chain.append(msg -> msg.then("-------------------------------------------------------"));
for (Message m : chain) {
Bukkit.getConsoleSender().spigot().sendMessage(m.build());
}
getServer().getPluginManager().disablePlugin(this);
return true;
} else {
LabyrinthProvider.getInstance().getContainer(STATE).delete("toString");
}
}
}
return false;
}

public void onDisable() {
Expand Down Expand Up @@ -322,6 +343,16 @@ public Optional<Clan.Associate> getAssociate(String playerName) {
return gallery;
}

@Override
public @NotNull PasteManager getPasteManager() {
return PasteManager.getInstance();
}

@Override
public @NotNull Hastebin getLocalHastebinInstance() {
return hastebin;
}

@Override
public boolean isUpdated() {
ClansUpdate update = new ClansUpdate(getPlugin());
Expand Down Expand Up @@ -432,6 +463,7 @@ public Menu getMenu(GUI gui, InvasiveEntity entity) {

void initialize() {
origin = FileList.search(PRO = this);
hastebin = getPasteManager().newHaste();
STATE = new NamespacedKey(this, "online-state");
sessionId = UUID.randomUUID();
Bukkit.getServicesManager().register(ClansAPI.class, this, this, ServicePriority.Normal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,14 @@ public static Quest[] getDefaults() {
barter.setReward(Reward.ITEM_ARRAY, new ItemStack[]{new ItemStack(Material.MAP), Items.edit().setType(Material.ENCHANTED_BOOK).addEnchantment(Enchantment.MENDING, 1).build()});
Quest diamond = Quest.newQuest("Diamond Back", "Mine 250 diamonds", 0, 250);
diamond.setReward(Reward.MONEY, 2569.69);
Quest lumberjack = Quest.newQuest("Lumberjack", "Obtain 2 stacks of wood", 0, 128);
Quest lumberjack = Quest.newQuest("Lumberjack", "Obtain 2 stacks of wood", 0, 128);
lumberjack.setReward(Reward.ITEM, Items.edit().setType(Material.ENCHANTED_BOOK).addEnchantment(Enchantment.DIG_SPEED, 3).build());
Quest dark = Quest.newQuest("Dark Soldier", "Kill 25 wither skeleton", 0, 25);
dark.setReward(Reward.ITEM, Items.edit().setType(Material.ENCHANTED_BOOK).addEnchantment(Enchantment.LOOT_BONUS_BLOCKS, 3).build());
Quest city = Quest.newQuest("Down Upside", "Locate and traverse an end city", 0, 1);
city.setReward(Reward.ITEM_ARRAY, new ItemStack[]{new ItemStack(Material.MAP), Items.edit().setType(Material.ENCHANTED_BOOK).addEnchantment(Enchantment.MENDING, 1).build()});
Quest chunk = Quest.newQuest("Chunk 007", "Locate and conquer 7 enemy claims.", 0, 7);
chunk.setReward(Reward.ITEM_ARRAY, new ItemStack[]{new ItemStack(Material.DIAMOND, 8), new ItemStack(Material.IRON_INGOT, 128), new ItemStack(Material.EXPERIENCE_BOTTLE, Math.max(1, new Random().nextInt(14)))});
return new Quest[]{walls, gate, kills, spawner, farmer, beef, sky, color, miner, breaker, hotfeet, souless, dirt, barter, diamond, lumberjack, dark, city};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public ItemStack[] get() {

@Override
public BaseComponent[] getMessage() {
return message().append(text("[").color(Color.BLUE)).append(text("Item's").color(Color.GREEN).bind(hover(get()[0]))).append(text("]").color(Color.BLUE)).append(text(" ")).append(text(get()[0].getType() + " + " + (get().length - 2) + " more items has been received.").color(Color.ORANGE)).build();
return message().append(text("[").color(Color.BLUE)).append(text("Item's").color(Color.GREEN).bind(hover(get()[0]))).append(text("]").color(Color.BLUE)).append(text(" ")).append(text(get()[0].getType() + " + " + (get().length - 1) + " more items has been received.").color(Color.ORANGE)).build();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.github.sanctum.clans.bridge.ClanAddon;
import com.github.sanctum.clans.bridge.ClanAddonQuery;
import com.github.sanctum.clans.bridge.internal.KingdomAddon;
import com.github.sanctum.clans.construct.RankPriority;
import com.github.sanctum.clans.construct.api.Claim;
import com.github.sanctum.clans.construct.api.Clan;
import com.github.sanctum.clans.construct.api.ClansAPI;
import com.github.sanctum.clans.construct.api.Clearance;
import com.github.sanctum.labyrinth.data.FileManager;
import com.github.sanctum.labyrinth.data.FileType;
import com.github.sanctum.labyrinth.data.Node;
Expand All @@ -21,15 +23,23 @@
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.intellij.lang.annotations.MagicConstant;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class RoundTable extends Progressive implements Iterable<Clan.Associate> {

public static final String INVITE = "INVITE";
public static final String TAG = "TAG";
public static final String PROMOTE = "PROMOTE";
public static final String DEMOTE = "DEMOTE";
public static final String KICK = "KICK";

private final String name;
private final Map<UUID, Rank> users = new HashMap<>();
private final Map<UUID, RankPriority> users = new HashMap<>();
private final Set<UUID> invites = new HashSet<>();
private final List<Quest> quests = new LinkedList<>();
private final Map<String, Clearance> perms = new HashMap<>();

public RoundTable(KingdomAddon cycle) {

Expand All @@ -52,7 +62,7 @@ public RoundTable(KingdomAddon cycle) {
if (!users.getRoot().getKeys(false).isEmpty()) {
for (String user : users.getRoot().getKeys(false)) {
UUID id = UUID.fromString(user);
this.users.put(id, Rank.valueOf(users.getRoot().getString(user + ".rank")));
this.users.put(id, RankPriority.valueOf(users.getRoot().getString(user + ".rank")));
}
}

Expand All @@ -62,6 +72,19 @@ public RoundTable(KingdomAddon cycle) {
loadQuest(Kingdom.getDefaults());
}

if (perms.isEmpty()) {
Clearance invite = new Clearance(2, "INVITE");
Clearance tag = new Clearance(1, "TAG");
Clearance promote = new Clearance(3, "PROMOTE");
Clearance demote = new Clearance(3, "DEMOTE");
Clearance kick = new Clearance(3, "KICK");
perms.put(invite.getName(), invite);
perms.put(tag.getName(), tag);
perms.put(promote.getName(), promote);
perms.put(demote.getName(), demote);
perms.put(kick.getName(), kick);
}

PROGRESSIVES.add(this);
}

Expand All @@ -81,48 +104,6 @@ public Spliterator<Clan.Associate> spliterator() {
return users.keySet().stream().map(u -> ClansAPI.getInstance().getAssociate(u).get()).collect(Collectors.toList()).spliterator();
}

public enum Permission {

INVITE(3),
TAG(2),
PROMOTE(4),
DEMOTE(4),
KICK(4);

private final int requirement;

Permission(int requirement) {
this.requirement = requirement;
}

public int getRequirement() {
return this.requirement;
}

public boolean test(Clan.Associate associate) {
return associate.getPriority().toInt() >= requirement;
}

}

public enum Rank {

LOW(1),
HIGH(2),
HIGHER(3),
HIGHEST(4);

private final int level;

Rank(int level) {
this.level = level;
}

public int getLevel() {
return level;
}
}

public boolean isMember(UUID target) {
return users.containsKey(target);
}
Expand All @@ -142,13 +123,13 @@ public boolean join(UUID target) {

if (isMember(target)) return false;

take(target, Rank.LOW);
take(target, RankPriority.NORMAL);
this.invites.remove(target);

return true;
}

public void take(UUID target, Rank rank) {
public void take(UUID target, RankPriority rank) {
this.users.put(target, rank);
}

Expand Down Expand Up @@ -185,7 +166,11 @@ public Set<UUID> getUsers() {

}

public Rank getRank(UUID user) {
public Clearance getClearance(@MagicConstant(valuesFromClass = RoundTable.class) String id) {
return perms.get(id);
}

public RankPriority getRank(UUID user) {
return this.users.get(user);
}

Expand Down Expand Up @@ -228,7 +213,7 @@ public void save(ClanAddon cycle) {

FileManager users = cycle.getFile(FileType.JSON, "users", "data");

for (Map.Entry<UUID, Rank> entry : this.users.entrySet()) {
for (Map.Entry<UUID, RankPriority> entry : this.users.entrySet()) {
users.getRoot().set(entry.getKey().toString() + ".rank", entry.getValue().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.sanctum.clans.bridge.internal.kingdoms.RoundTable;
import com.github.sanctum.clans.bridge.internal.kingdoms.event.KingdomCreatedEvent;
import com.github.sanctum.clans.bridge.internal.kingdoms.event.KingdomCreationEvent;
import com.github.sanctum.clans.construct.RankPriority;
import com.github.sanctum.clans.construct.api.Clan;
import com.github.sanctum.clans.construct.api.ClanSubCommand;
import com.github.sanctum.clans.construct.api.ClansAPI;
Expand Down Expand Up @@ -417,7 +418,7 @@ public boolean player(Player p, String label, String[] args) {
if (table.getUsers().isEmpty()) {

if (EconomyProvision.getInstance().balance(p).orElse(0.0) >= 10000) {
table.take(p.getUniqueId(), RoundTable.Rank.HIGHEST);
table.take(p.getUniqueId(), RankPriority.HIGHEST);
addon.getMailer().prefix().start(Clan.ACTION.getPrefix()).finish().announce(player -> true, p.getName() + " is now among the most powerful on the server.").deploy();
} else {
Clan.ACTION.sendMessage(p, "&cYou aren't powerful enough to start the table.");
Expand Down
Loading

0 comments on commit 74e5b4c

Please sign in to comment.