Skip to content

Commit

Permalink
Merge pull request #29 from LewMC/1.4.0
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
lewmilburn authored Sep 24, 2024
2 parents 6cfc36b + f8c52d8 commit fad9416
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 96 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>net.lewmc</groupId>
<artifactId>kryptonite</artifactId>
<name>Kryptonite</name>
<version>1.4.0-SNAPSHOT</version>
<version>1.4.0</version>
<build>
<resources>
<resource>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.lewmc</groupId>
<artifactId>kryptonite</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>Kryptonite</name>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/lewmc/kryptonite/Kryptonite.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ private void initFilesystem() {
saveResource("profiles/YouHaveTrouble.kos", false);
}

File FFProfile = new File(getDataFolder() + File.separator + "profiles/FarmFriendly.kos");
if (!FFProfile.exists()) {
saveResource("profiles/FarmFriendly.kos", false);
}

File profilesFolder = new File(getDataFolder() + File.separator + "profiles");
if (!profilesFolder.exists()) {
if (!profilesFolder.mkdirs()) {
Expand Down Expand Up @@ -150,7 +155,6 @@ private void detectBadPlugins() {
this.log.severe("");
this.log.severe("Using known lag-causing plugin: "+badPlugin);
this.log.severe("This plugin may cause more lag than it resolves or conflict with Kryptonite. Consider removing it.");
this.log.severe("Learn more: https://wiki.lewmc.net/index.php/Lag_Plugins");
this.log.severe("");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public boolean onCommand(
}
} else {
message.Error("You do not have the required permissions to run this command.");
message.Error("Please visit https://wiki.lewmc.net/index.php/Kryptonite_Commands for more information.");
message.Error("Please visit https://wiki.lewmc.net/kr-commands.html for more information.");
}
return true;
}
Expand All @@ -187,7 +187,7 @@ private void checkAll(Check check) {
message.Warning("Many of these exploits require Paper to be patched, which you are not running.");
}

message.Info("More information: https://wiki.lewmc.net/index.php/Exploit_Database");
message.Info("More information: https://wiki.lewmc.net/kr-exploit-database.html");
}

private void complete(boolean passed, String code) {
Expand Down
57 changes: 29 additions & 28 deletions src/main/java/net/lewmc/kryptonite/commands/OptimiseCommand.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package net.lewmc.kryptonite.commands;

import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
import net.lewmc.kryptonite.Kryptonite;
import net.lewmc.kryptonite.kos.KOS;
import net.lewmc.kryptonite.kos.gui.KosMainGui;
import net.lewmc.kryptonite.utils.MessageUtil;
import net.lewmc.kryptonite.utils.PermissionUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import java.util.Objects;

Expand Down Expand Up @@ -43,31 +37,38 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
PermissionUtil perm = new PermissionUtil();

if (perm.isOperator(commandSender)) {
if (args.length == 1) {
if (Objects.equals(args[0].toLowerCase(), "yes")) {
message.Info("Kryptonite will now run it's optimisation system.");
message.Info("You should backup your server before running Kryptonite.");
message.Info("You'll need to restart the server after completion for changes to be made.");
message.Info("");
if (commandSender instanceof Player) {
KosMainGui gui = new KosMainGui(this.plugin, commandSender);
gui.show();
} else {
if (args.length == 1) {
if (Objects.equals(args[0].toLowerCase(), "yes")) {
message.Info("Kryptonite will now run it's optimisation system.");
message.Info("You should backup your server before running Kryptonite.");
message.Info("You'll need to restart the server after completion for changes to be made.");
message.Info("");
message.Info("Using profile '" + this.plugin.getConfig().getString("kos.default-profile") + "'");

KOS kos = new KOS(commandSender, this.plugin, this.plugin.getConfig().getString("kos.profile"));
kos.runDefault(true);
} else if (Objects.equals(args[0].toLowerCase(), "no") && perm.isOperator(commandSender)) {
message.Info("Kryptonite will now run it's optimisation system.");
message.Info("You should backup your server before running Kryptonite.");
message.Info("You'll need to restart the server after completion for changes to be made.");
message.Info("");
KOS kos = new KOS(commandSender, this.plugin, this.plugin.getConfig().getString("kos.default-profile"));
kos.runDefault(true);
} else if (Objects.equals(args[0].toLowerCase(), "no") && perm.isOperator(commandSender)) {
message.Info("Kryptonite will now run it's optimisation system.");
message.Info("You should backup your server before running Kryptonite.");
message.Info("You'll need to restart the server after completion for changes to be made.");
message.Info("");
message.Info("Using profile '" + this.plugin.getConfig().getString("kos.default-profile") + "'");

KOS kos = new KOS(commandSender, this.plugin, this.plugin.getConfig().getString("kos.profile"));
kos.runDefault(false);
} else {
message.Error("Unknown command. Use /kos for help.");
}
} else {
if (commandSender instanceof Player) {
KosMainGui gui = new KosMainGui(this.plugin, commandSender);
gui.show();
KOS kos = new KOS(commandSender, this.plugin, this.plugin.getConfig().getString("kos.default-profile"));
kos.runDefault(false);
} else {
message.Error("Unknown command. Use /kos for help.");
}
} else {
message.Info("--- KRYPTONITE OPTIMISATION SYSTEM ---");
message.Info("KOS will use the kos.default-profile value set in Kryptonite.yml");
message.Info("Please ensure this is correct before continuing.");
message.Info("Current profile: " + this.plugin.getConfig().getString("kos.default-profile"));
message.Info("");
message.Info("Have you pregenerated your world and set a vanilla world border?");
message.Info("This will affect which optimisations can be applied.");
message.Info("");
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/net/lewmc/kryptonite/kos/KOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,36 +199,36 @@ private void runPaper(boolean pregeneratedWorld) {
);

pw.ambientDespawnRanges(
this.patches.getInt("paper.despawn-ranges.ambient.hard"),
this.patches.getInt("paper.despawn-ranges.ambient.soft")
this.patches.get("paper.despawn-ranges.ambient.hard"),
this.patches.get("paper.despawn-ranges.ambient.soft")
);
pw.axolotlsDespawnRanges(
this.patches.getInt("paper.despawn-ranges.axolotl.hard"),
this.patches.getInt("paper.despawn-ranges.axolotl.soft")
this.patches.get("paper.despawn-ranges.axolotl.hard"),
this.patches.get("paper.despawn-ranges.axolotl.soft")
);
pw.creatureDespawnRanges(
this.patches.getInt("paper.despawn-ranges.creature.hard"),
this.patches.getInt("paper.despawn-ranges.creature.soft")
this.patches.get("paper.despawn-ranges.creature.hard"),
this.patches.get("paper.despawn-ranges.creature.soft")
);
pw.miscDespawnRanges(
this.patches.getInt("paper.despawn-ranges.misc.hard"),
this.patches.getInt("paper.despawn-ranges.misc.soft")
this.patches.get("paper.despawn-ranges.misc.hard"),
this.patches.get("paper.despawn-ranges.misc.soft")
);
pw.monsterDespawnRanges(
this.patches.getInt("paper.despawn-ranges.monster.hard"),
this.patches.getInt("paper.despawn-ranges.monster.soft")
this.patches.get("paper.despawn-ranges.monster.hard"),
this.patches.get("paper.despawn-ranges.monster.soft")
);
pw.undergroundWaterCreatureDespawnRanges(
this.patches.getInt("paper.despawn-ranges.water.underground-creature.hard"),
this.patches.getInt("paper.despawn-ranges.water.underground-creature.soft")
this.patches.get("paper.despawn-ranges.water.underground-creature.hard"),
this.patches.get("paper.despawn-ranges.water.underground-creature.soft")
);
pw.waterAmbientDespawnRanges(
this.patches.getInt("paper.despawn-ranges.water.ambient.hard"),
this.patches.getInt("paper.despawn-ranges.water.ambient.soft")
this.patches.get("paper.despawn-ranges.water.ambient.hard"),
this.patches.get("paper.despawn-ranges.water.ambient.soft")
);
pw.waterCreatureDespawnRanges(
this.patches.getInt("paper.despawn-ranges.water.creature.hard"),
this.patches.getInt("paper.despawn-ranges.water.creature.soft")
this.patches.get("paper.despawn-ranges.water.creature.hard"),
this.patches.get("paper.despawn-ranges.water.creature.soft")
);

pw.perPlayerMobSpawns(this.patches.getBoolean("paper.per-player-mob-spawns"));
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/lewmc/kryptonite/kos/config/PaperWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,42 @@ public void entityPerChunkSaveLimit(int areaEffectCloud,
this.plugin.getConfig().set("chunks.entity-per-chunk-save-limit.wither_skull", witherSkull);
}

public void ambientDespawnRanges(int hard, int soft) {
public void ambientDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.ambient.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.ambient.soft", soft);
}

public void axolotlsDespawnRanges(int hard, int soft) {
public void axolotlsDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.axolotls.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.axolotls.soft", soft);
}

public void creatureDespawnRanges(int hard, int soft) {
public void creatureDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.creature.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.creature.soft", soft);
}

public void miscDespawnRanges(int hard, int soft) {
public void miscDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.misc.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.misc.soft", soft);
}

public void monsterDespawnRanges(int hard, int soft) {
public void monsterDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.monster.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.monster.soft", soft);
}

public void undergroundWaterCreatureDespawnRanges(int hard, int soft) {
public void undergroundWaterCreatureDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.underground_water_creature.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.underground_water_creature.soft", soft);
}

public void waterAmbientDespawnRanges(int hard, int soft) {
public void waterAmbientDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.water_ambient.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.water_ambient.soft", soft);
}

public void waterCreatureDespawnRanges(int hard, int soft) {
public void waterCreatureDespawnRanges(Object hard, Object soft) {
this.plugin.getConfig().set("entities.spawning.despawn-ranges.water_creature.hard", hard);
this.plugin.getConfig().set("entities.spawning.despawn-ranges.water_creature.soft", soft);
}
Expand Down
110 changes: 79 additions & 31 deletions src/main/java/net/lewmc/kryptonite/kos/gui/KosMainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
import de.themoep.inventorygui.InventoryGui;
import de.themoep.inventorygui.StaticGuiElement;
import net.lewmc.kryptonite.Kryptonite;
import net.lewmc.kryptonite.utils.ConfigurationUtil;
import net.lewmc.kryptonite.utils.MessageUtil;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

import java.io.File;

/**
* The main menu GUI for KOS.
*/
Expand All @@ -33,10 +38,13 @@ public KosMainGui(Kryptonite plugin, CommandSender commandSender) {
*/
public void show() {
InventoryHolder holder = this.commandSender.getServer().getPlayer(this.commandSender.getName());
this.gui = new InventoryGui(this.plugin, holder, "KOS - Select a Profile", this.getElements());
char[] chars = this.addElements(false);

this.gui = new InventoryGui(this.plugin, holder, "KOS - Select a Profile", this.getElements(chars));

this.addElements(true);

this.gui.setFiller(new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1));
this.addElements();

this.gui.build();
this.gui.show((Player) this.commandSender);
Expand All @@ -45,41 +53,81 @@ public void show() {
/**
* Adds pre-programmed elements to the GUI
*/
private void addElements() {
this.gui.addElement(new StaticGuiElement('y',
new ItemStack(Material.OAK_SIGN),
1,
click -> {
click.getGui().close();
KosPregeneratedGui kpg = new KosPregeneratedGui(this.plugin, this.commandSender, "YouHaveTrouble");
kpg.show();
return true;
},
"YouHaveTrouble"
));

this.gui.addElement(new StaticGuiElement('h',
new ItemStack(Material.PAPER),
1,
click -> {
click.getWhoClicked().sendMessage(ChatColor.YELLOW+"https://wiki.lewmc.net/kr-kryptonite-optimisation-system.html");
click.getGui().close();
return true;
},
"Need help?",
"Click here to get a link to our Wiki."
));
private char[] addElements(boolean addToGui) {
File dir = new File(this.plugin.getDataFolder() + "/profiles");
File[] directoryListing = dir.listFiles();
char firstChar = 'a';
char[] chars = new char[directoryListing.length];
if (directoryListing != null) {
int index = 0;
for (File child : directoryListing) {
if (child.getName().contains(".kos")) {
ConfigurationUtil cfg = new ConfigurationUtil(this.plugin, commandSender);
YamlConfiguration item = cfg.load(this.plugin.getDataFolder() + "/profiles/"+child.getName());
chars[index] = firstChar;
if (addToGui) {
this.gui.addElement(new StaticGuiElement(firstChar,
new ItemStack(Material.OAK_SIGN),
1,
click -> {
click.getGui().close();
KosPregeneratedGui kpg = new KosPregeneratedGui(this.plugin, this.commandSender, child.getName().replace(".kos", ""));
kpg.show();
return true;
},
child.getName().replace(".kos", ""),
item.getString("meta.description"),
"Created by " + item.getString("meta.author")
));
}
index++;
firstChar++;
}
}
} else {
MessageUtil msg = new MessageUtil(this.commandSender);
msg.Error("Unable to find any installed KOS profiles.");
}

if (addToGui) {
this.gui.addElement(new StaticGuiElement('h',
new ItemStack(Material.PAPER),
1,
click -> {
click.getWhoClicked().sendMessage(ChatColor.YELLOW + "https://wiki.lewmc.net/kr-kryptonite-optimisation-system.html");
click.getGui().close();
return true;
},
"Need help?",
"Click here to get a link to our Wiki."
));
}

return chars;
}

/**
* Determines where the elements should be positioned.
* @return String[] - The position of the elements.
* @return chars[] - The characters used.
*/
private String[] getElements() {
private String[] getElements(char[] chars) {
StringBuilder line1 = new StringBuilder(" ");
StringBuilder line2 = new StringBuilder(" ");
String line3 = " h ";

int i = 0;
for (; i < chars.length && i < 9; i++) {
line1.setCharAt(i, chars[i]);
}

for (int j = 0; i < chars.length && j < 9; i++, j++) {
line2.setCharAt(j, chars[i]);
}

return new String[]{
" y ",
" ",
" h "
line1.toString(),
line2.toString(),
line3
};
}
}
Loading

0 comments on commit fad9416

Please sign in to comment.