Files
src
build.gradle
README.txt
settings.gradle
Code
11 1,023
src/main/java/com/splashsmp/SplashSMP.java
package com.splashsmp;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
public class SplashSMP extends JavaPlugin implements Listener, CommandExecutor {
private ProfileManager profiles;
private ItemFactory items;
private SmpListener smpListener;
private PhotosynthesisService photosynthesis;
@Override
public void onEnable() {
getDataFolder().mkdirs();
profiles = new ProfileManager(this);
items = new ItemFactory(this);
smpListener = new SmpListener(this, profiles, items);
photosynthesis = new PhotosynthesisService(items);
Bukkit.getPluginManager().registerEvents(smpListener, this);
Bukkit.getPluginManager().registerEvents(photosynthesis, this);
getCommand("stage").setExecutor(this);
getCommand("withdraw").setExecutor(this);
registerRerollRecipe();
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (Player player : Bukkit.getOnlinePlayers()) {
smpListener.tick(player);
photosynthesis.repairInSunlight(player);
}
}, 20L, 20L);
}
@Override
public void onDisable() {
if (profiles != null) {
profiles.save();
}
Bukkit.removeRecipe(new NamespacedKey(this, "skill_reroll_recipe"));
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("This command can only be used by a player.");
return true;
}
PlayerProfile profile = profiles.get(player);
if (command.getName().equalsIgnoreCase("stage")) {
player.sendMessage("§bSkill: §f" + profile.getSkill().displayName() + " §7| §bStage: §f" + profile.getStage() + "/5");
player.sendMessage("§7" + profile.getSkill().description());
player.sendMessage("§7Double-sneak to activate your skill.");
return true;
}
if (command.getName().equalsIgnoreCase("withdraw")) {
smpListener.withdrawStage(player);
return true;
}
return false;
}
private void registerRerollRecipe() {
ItemStack result = items.rerollItem();
NamespacedKey key = new NamespacedKey(this, "skill_reroll_recipe");
ShapedRecipe recipe = new ShapedRecipe(key, result);
recipe.shape("IGI", "GDI", "IGI");
recipe.setIngredient('I', XMaterial.matchXMaterial("IRON_BLOCK").map(XMaterial::parseMaterial).orElseThrow());
recipe.setIngredient('G', XMaterial.matchXMaterial("GOLD_BLOCK").map(XMaterial::parseMaterial).orElseThrow());
recipe.setIngredient('D', XMaterial.matchXMaterial("DIAMOND_BLOCK").map(XMaterial::parseMaterial).orElseThrow());
Bukkit.addRecipe(recipe);
}
public void repairPhotosynthesis(Player player) {
photosynthesis.repairInSunlight(player);
}
}