Skip to content

Commit

Permalink
1.5-R1 - Added Advancements Messages - Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CroaBeast committed Jan 5, 2022
1 parent e9fd06c commit a34c305
Show file tree
Hide file tree
Showing 27 changed files with 590 additions and 166 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@

<groupId>me.croabeast</groupId>
<artifactId>SIR_Plugin</artifactId>
<version>1.4-R9</version>
<version>1.5-R1</version>
<packaging>jar</packaging>

<name>SIR_Plugin</name> <!--Simple In-game Receptionist-->
Expand Down
30 changes: 18 additions & 12 deletions src/main/java/me/croabeast/iridiumapi/IridiumAPI.java
Expand Up @@ -96,19 +96,25 @@ private static String apply(@NotNull String source, ChatColor[] colors) {
String[] characters = source.split("");

int outIndex = 0;
for (int i = 0; i < characters.length; i++) {
if ((characters[i].equals("&") || characters[i].equals("§"))
&& i + 1 < characters.length) {
if (!characters[i + 1].equals("r")) {
specialColors.append(characters[i]);
specialColors.append(characters[i + 1]);
try {
for (int i = 0; i < characters.length; i++) {
if ((characters[i].equals("&") || characters[i].equals("§"))
&& i + 1 < characters.length || colors == null) {
if (!characters[i + 1].equals("r")) {
specialColors.append(characters[i]);
specialColors.append(characters[i + 1]);
}
else specialColors.setLength(0);
i++;
}
else specialColors.setLength(0);
i++;
else stringBuilder.append(colors[outIndex++])
.append(specialColors).append(characters[i]);
}
else stringBuilder.append(colors[outIndex++])
.append(specialColors).append(characters[i]);
}
catch (IndexOutOfBoundsException e) {
return source;
}

return stringBuilder.toString();
}

Expand All @@ -120,8 +126,8 @@ private static String withoutSpecialChar(@NotNull String source) {
return workingString;
}

@NotNull
private static ChatColor[] createRainbow(int step, float saturation) {
if (step == 0) return null;
ChatColor[] colors = new ChatColor[step];
double colorStep = (1.00 / step);

Expand All @@ -132,8 +138,8 @@ private static ChatColor[] createRainbow(int step, float saturation) {
return colors;
}

@NotNull
private static ChatColor[] createGradient(@NotNull Color start, @NotNull Color end, int step) {
if (step == 1) return null;
ChatColor[] colors = new ChatColor[step];
int stepR = Math.abs(start.getRed() - end.getRed()) / (step - 1);
int stepG = Math.abs(start.getGreen() - end.getGreen()) / (step - 1);
Expand Down
77 changes: 59 additions & 18 deletions src/main/java/me/croabeast/sircore/Application.java
Expand Up @@ -12,6 +12,7 @@
import org.jetbrains.annotations.*;

import java.util.*;
import java.util.stream.Stream;

public final class Application extends JavaPlugin {

Expand Down Expand Up @@ -64,11 +65,15 @@ public void onEnable() {
files.loadFiles(true);
init.setPluginHooks();
init.registerListeners();

reporter.startTask();
recorder.doRecord("&7The announcement task has been started.");

init.loadAdvances();

recorder.doRecord("&7The announcement task has been started.", "",
recorder.doRecord("",
"&7SIR " + PLUGIN_VERSION + " was&a loaded&7 in " +
(System.currentTimeMillis() - start) + " ms."
(System.currentTimeMillis() - start) + " ms."
);
recorder.rawRecord("");

Expand All @@ -78,7 +83,10 @@ public void onEnable() {
@Override
public void onDisable() {
pluginHeader();

init.unloadAdvances();
reporter.cancelTask();

recorder.doRecord(
"&7The announcement task has been stopped.",
"&7SIR &c" + PLUGIN_VERSION + "&7 was totally disabled.",
Expand All @@ -98,23 +106,58 @@ public List<Player> everyPlayer() {
return new ArrayList<>(Bukkit.getOnlinePlayers());
}

@NotNull public FileConfiguration getConfig() { return files.getFile("config"); }
public FileConfiguration getChat() { return files.getFile("chat"); }
public FileConfiguration getAnnounces() { return files.getFile("announces"); }
public FileConfiguration getLang() { return files.getFile("lang"); }
public FileConfiguration getMessages() { return files.getFile("messages"); }
public FileConfiguration getMOTD() { return files.getFile("motd"); }
public FileConfiguration getDiscord() { return files.getFile("discord"); }
@NotNull
public FileConfiguration getConfig() {
return files.getFile("config");
}
public FileConfiguration getAdvances() {
return files.getFile("advances");
}
public FileConfiguration getChat() {
return files.getFile("chat");
}
public FileConfiguration getAnnounces() {
return files.getFile("announces");
}
public FileConfiguration getLang() {
return files.getFile("lang");
}
public FileConfiguration getMessages() {
return files.getFile("messages");
}
public FileConfiguration getMOTD() {
return files.getFile("motd");
}
public FileConfiguration getDiscord() {
return files.getFile("discord");
}

public Recorder getRecorder() { return recorder; }
public Initializer getInitializer() { return init; }
public Recorder getRecorder() {
return recorder;
}
public Initializer getInitializer() {
return init;
}

public TextUtils getTextUtils() { return text; }
public PermUtils getPermUtils() { return perms; }
public EventUtils getEventUtils() { return utils; }
public FilesUtils getFiles() {
return files;
}
public TextUtils getTextUtils() {
return text;
}
public PermUtils getPermUtils() {
return perms;
}
public EventUtils getEventUtils() {
return utils;
}

public Amender getAmender() { return amender; }
public Reporter getReporter() { return reporter; }
public Amender getAmender() {
return amender;
}
public Reporter getReporter() {
return reporter;
}

public Plugin getPlugin(String name) {
return Bukkit.getPluginManager().getPlugin(name);
Expand All @@ -128,6 +171,4 @@ public void registerListener(Listener listener, boolean addListener) {
public void registerListener(Listener listener) {
registerListener(listener, true);
}

public void reloadFiles() { files.loadFiles(false); }
}
92 changes: 84 additions & 8 deletions src/main/java/me/croabeast/sircore/Initializer.java
Expand Up @@ -6,6 +6,8 @@
import me.croabeast.sircore.objects.*;
import me.croabeast.sircore.utilities.*;
import net.milkbowl.vault.permission.*;
import org.bukkit.*;
import org.bukkit.advancement.*;
import org.bukkit.plugin.*;

import java.util.*;
Expand All @@ -18,15 +20,12 @@ public class Initializer {

public int LISTENERS = 0;

public boolean HAS_PAPI, HAS_VAULT,
DISCORD, HAS_LOGIN, HAS_VANISH;
public boolean HAS_PAPI, HAS_VAULT, DISCORD, HAS_LOGIN, HAS_VANISH,
authMe, userLogin, hasCMI, essentials, srVanish, prVanish;

protected List<String> LOGIN_HOOKS = new ArrayList<>(),
VANISH_HOOKS = new ArrayList<>();

public boolean authMe, userLogin, hasCMI,
essentials, srVanish, prVanish;

public Initializer(Application main) {
this.main = main;
recorder = main.getRecorder();
Expand All @@ -44,7 +43,9 @@ public Initializer(Application main) {
prVanish = isHooked("PremiumVanish", VANISH_HOOKS);
}

private boolean isPlugin(String name) { return main.getPlugin(name) != null; }
private boolean isPlugin(String name) {
return main.getPlugin(name) != null;
}

private boolean isHooked(String name, List<String> hookList) {
if (!isPlugin(name)) return false;
Expand Down Expand Up @@ -166,21 +167,94 @@ public void registerListeners() {
new PlayerListener(main);
new MOTDListener(main);
new FormatListener(main);
new Advancements(main);

if (HAS_LOGIN) new LoginListener(main);
if (HAS_VANISH) new VanishListener(main);

recorder.doRecord("&7Registered &e" + LISTENERS + "&7 plugin's listeners.");
}

@SuppressWarnings("deprecation")
public void loadAdvances() {
if (main.MC_VERSION < 12) return;

long time = System.currentTimeMillis();
recorder.doRecord("", "&bLoading all the advancements...");

for (World world : main.getServer().getWorlds()) {
if (main.MC_VERSION == 12) {
world.setGameRuleValue("ANNOUNCE_ADVANCEMENTS", "false");
continue;
}
world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, false);
}

Set<String> tasks = new HashSet<>(), goals = new HashSet<>(),
challenges = new HashSet<>(), keys = new HashSet<>();
Iterator<Advancement> progress = main.getServer().advancementIterator();

while (progress.hasNext()) {
Advancement adv = progress.next();
String key = main.getTextUtils().stringKey(adv.getKey().toString());
String type = new Advancements.ReflectKeys(adv).getFrameType();

if (key.contains("root") || key.contains("recipes")) continue;
boolean notContained = !main.getAdvances().contains(key);

if (type.matches("(?i)CHALLENGE")) {
challenges.add(key);
if (notContained) {
main.getAdvances().set(key, "type.challenge");
keys.add(key);
}
}
else if (type.matches("(?i)TASK")) {
tasks.add(key);
if (notContained) {
main.getAdvances().set(key, "type.task");
keys.add(key);
}
}
else if (type.matches("(?i)GOAL")) {
goals.add(key);
if (notContained) {
main.getAdvances().set(key, "type.goal");
keys.add(key);
}
}
}

if (keys.size() > 0) main.getFiles().getObject("advances").saveFile();
recorder.doRecord(
"&7Tasks: &a" + tasks.size() + "&7 - Goals: &b" + goals.size() + "&7 - " +
"&7Challenges: &d" + challenges.size(), // haha, I hate those empty gaps lmao
"&7Registered advancements in &e" + (System.currentTimeMillis() - time) + "&7 ms."
);
}

@SuppressWarnings("deprecation")
public void unloadAdvances() {
if (main.MC_VERSION < 12) return;

for (World world : main.getServer().getWorlds()) {
if (main.MC_VERSION == 12) {
world.setGameRuleValue("ANNOUNCE_ADVANCEMENTS", "true");
continue;
}
world.setGameRule(GameRule.ANNOUNCE_ADVANCEMENTS, true);
}
}

private void showPluginInfo(String name) {
String pluginVersion;
String isHooked;

if (isPlugin(name)) {
pluginVersion = main.getPlugin(name).getDescription().getVersion();
isHooked = " &aenabled&7. Hooking...";
} else {
}
else {
pluginVersion = "";
isHooked = "&cnot found&7. Unhooking...";
}
Expand All @@ -193,6 +267,8 @@ public Guild discordServer() {
String server = main.getDiscord().getString("server-id", "");
return DiscordSRV.getPlugin().getJda().getGuildById(server);
}
catch (Exception e) { return null; }
catch (Exception e) {
return null;
}
}
}

0 comments on commit a34c305

Please sign in to comment.