Compare commits
11 Commits
april_fool
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb98c3761b | ||
|
|
df347fde7f | ||
|
|
ab162b5094 | ||
|
|
c66b30ff90 | ||
|
|
7625c57b8b | ||
|
|
7f6d4c4b36 | ||
|
|
d6d7269fee | ||
|
|
e81d532178 | ||
|
|
c016db5969 | ||
|
|
05fd3beb9c | ||
|
|
f80645e2fe |
|
|
@ -1,6 +1,7 @@
|
|||
plugins {
|
||||
id("java")
|
||||
id("maven-publish")
|
||||
id("com.github.ben-manes.versions") version "0.52.0"
|
||||
}
|
||||
|
||||
group = "com.alttd"
|
||||
|
|
@ -38,7 +39,12 @@ tasks {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
|
||||
compileOnly("com.alttd.cosmos:cosmos-api:1.21.10-R0.1-SNAPSHOT") {
|
||||
isChanging = true
|
||||
}
|
||||
|
||||
implementation("org.slf4j:slf4j-api:2.0.17")
|
||||
|
||||
compileOnly("org.projectlombok:lombok:1.18.38")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.38")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,21 @@
|
|||
rootProject.name = "PlayerUtils"
|
||||
rootProject.name = "StaffUtils"
|
||||
|
||||
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME")
|
||||
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD")
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||
maven("'https://jitpack.io'") // Vault
|
||||
maven {
|
||||
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||
credentials {
|
||||
username = nexusUser
|
||||
password = nexusPass
|
||||
}
|
||||
}
|
||||
maven("https://repo.destro.xyz/snapshots")
|
||||
maven("https://jitpack.io")
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.alttd.playerutils;
|
||||
|
||||
import com.alttd.playerutils.commands.PlayerUtilsCommand;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.GhastSpeed;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.RotateBlock;
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.config.KeyStorage;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.event_listeners.*;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
|
@ -15,12 +15,10 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public final class PlayerUtils extends JavaPlugin {
|
||||
|
||||
private Logger logger;
|
||||
private PlayerUtilsCommand playerUtilsCommand;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
this.logger = new Logger(getLogger());
|
||||
registerCommands();
|
||||
registerEvents();
|
||||
reloadConfigs();
|
||||
|
|
@ -33,25 +31,31 @@ public final class PlayerUtils extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerCommands() {
|
||||
playerUtilsCommand = new PlayerUtilsCommand(this, logger);
|
||||
playerUtilsCommand = new PlayerUtilsCommand(this);
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
PluginManager pluginManager = getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new XpBottleEvent(this, logger), this);
|
||||
pluginManager.registerEvents(new XpBottleEvent(this), this);
|
||||
pluginManager.registerEvents(new TeleportEvent(), this);
|
||||
pluginManager.registerEvents(new GoatHornEvent(logger), this);
|
||||
pluginManager.registerEvents(new LimitArmorStands(this, logger), this);
|
||||
pluginManager.registerEvents(new GoatHornEvent(), this);
|
||||
pluginManager.registerEvents(new LimitArmorStands(this), this);
|
||||
pluginManager.registerEvents(new BlockBlockUseEvent(), this);
|
||||
pluginManager.registerEvents(new PlayerJoin(this), this);
|
||||
|
||||
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent(logger);
|
||||
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent();
|
||||
pluginManager.registerEvents(rotateBlockEvent, this);
|
||||
playerUtilsCommand.addSubCommand(new RotateBlock(rotateBlockEvent));
|
||||
|
||||
GhastSpeedEvent ghastSpeedEvent = new GhastSpeedEvent();
|
||||
pluginManager.registerEvents(ghastSpeedEvent, this);
|
||||
playerUtilsCommand.addSubCommand(new GhastSpeed(ghastSpeedEvent));
|
||||
}
|
||||
|
||||
public void reloadConfigs() {
|
||||
Config.reload(logger);
|
||||
Messages.reload(logger);
|
||||
KeyStorage.reload(logger);
|
||||
Config.reload();
|
||||
Messages.reload();
|
||||
KeyStorage.reload();
|
||||
}
|
||||
|
||||
private void registerSchedulers() {
|
||||
|
|
|
|||
|
|
@ -3,26 +3,26 @@ package com.alttd.playerutils.commands;
|
|||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.commands.playerutils_subcommands.*;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.event_listeners.RotateBlockEvent;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j @Getter
|
||||
public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
||||
private final List<SubCommand> subCommands;
|
||||
|
||||
public PlayerUtilsCommand(PlayerUtils playerUtils, Logger logger) {
|
||||
public PlayerUtilsCommand(PlayerUtils playerUtils) {
|
||||
PluginCommand command = playerUtils.getCommand("playerutils");
|
||||
if (command == null) {
|
||||
subCommands = null;
|
||||
logger.severe("Unable to find playerutils command.");
|
||||
log.error("Unable to find playerutils command.");
|
||||
return;
|
||||
}
|
||||
command.setExecutor(this);
|
||||
|
|
@ -30,11 +30,11 @@ public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
|||
command.setAliases(List.of("pu"));
|
||||
|
||||
subCommands = new ArrayList<>(List.of(
|
||||
new Glow(logger),
|
||||
new Glow(),
|
||||
new XPCheque(playerUtils),
|
||||
new XPCalc(),
|
||||
new Reload(playerUtils),
|
||||
new Key(logger))
|
||||
new Key())
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -85,10 +85,6 @@ public class PlayerUtilsCommand implements CommandExecutor, TabExecutor {
|
|||
return res;
|
||||
}
|
||||
|
||||
public List<SubCommand> getSubCommands() {
|
||||
return subCommands;
|
||||
}
|
||||
|
||||
private SubCommand getSubCommand(String cmdName) {
|
||||
return subCommands.stream()
|
||||
.filter(subCommand -> subCommand.getName().equals(cmdName))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.alttd.playerutils.commands.argument_parser;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ArgumentParser<T> {
|
||||
|
||||
Optional<T> parse(CommandSender commandSender, String argument);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.alttd.playerutils.commands.argument_parser;
|
||||
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.data_objects.GHAST_SPEED;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class GhastSpeedParser implements ArgumentParser<GHAST_SPEED> {
|
||||
|
||||
@Override
|
||||
public Optional<GHAST_SPEED> parse(CommandSender commandSender, String speed) {
|
||||
GHAST_SPEED ghastSpeed;
|
||||
try {
|
||||
ghastSpeed = GHAST_SPEED.valueOf(speed.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(ghastSpeed);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.alttd.playerutils.commands.argument_parser;
|
||||
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class OnlinePlayerParser implements ArgumentParser<Player> {
|
||||
|
||||
@Override
|
||||
public Optional<Player> parse(CommandSender commandSender, String playerName) {
|
||||
Player player = commandSender.getServer().getPlayer(playerName);
|
||||
if (player == null || !player.isOnline()) {
|
||||
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_NOT_FOUND, Placeholder.parsed("player", playerName));
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(player);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package com.alttd.playerutils.commands.playerutils_subcommands;
|
||||
|
||||
import com.alttd.playerutils.commands.SubCommand;
|
||||
import com.alttd.playerutils.commands.argument_parser.GhastSpeedParser;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.data_objects.GHAST_SPEED;
|
||||
import com.alttd.playerutils.event_listeners.GhastSpeedEvent;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.HappyGhast;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GhastSpeed extends SubCommand {
|
||||
|
||||
private final static GhastSpeedParser GHAST_SPEED_PARSER = new GhastSpeedParser();
|
||||
private final static int GHAST_SPEED_ARG = 1;
|
||||
|
||||
private final GhastSpeedEvent ghastSpeedEvent;
|
||||
|
||||
public GhastSpeed(GhastSpeedEvent ghastSpeedEvent) {
|
||||
this.ghastSpeedEvent = ghastSpeedEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
if (args.length != 2) {
|
||||
return false;
|
||||
}
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
|
||||
return true;
|
||||
}
|
||||
Optional<GHAST_SPEED> parsedGhastSpeed = GHAST_SPEED_PARSER.parse(commandSender, args[GHAST_SPEED_ARG]);
|
||||
if (parsedGhastSpeed.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
GHAST_SPEED ghastSpeed = parsedGhastSpeed.get();
|
||||
if (!(player.getVehicle() instanceof HappyGhast happyGhast)) {
|
||||
commandSender.sendRichMessage(Messages.GHAST_SPEED.NOT_RIDING_A_GHAST);
|
||||
return true;
|
||||
}
|
||||
|
||||
AttributeInstance attribute = happyGhast.getAttribute(Attribute.FLYING_SPEED);
|
||||
if (attribute == null) {
|
||||
commandSender.sendRichMessage(Messages.GHAST_SPEED.FAILED_TO_SET_SPEED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!commandSender.hasPermission(getPermission() + "." + ghastSpeed.name().toLowerCase())) {
|
||||
commandSender.sendRichMessage(Messages.GENERIC.NO_PERMISSION,
|
||||
Placeholder.parsed("permission", getPermission() + "." +
|
||||
ghastSpeed.name().toLowerCase()));
|
||||
return true;
|
||||
}
|
||||
|
||||
double newSpeed = GHAST_SPEED.getSpeed(ghastSpeed);
|
||||
|
||||
ghastSpeedEvent.setNewSpeed(player.getUniqueId(), ghastSpeed);
|
||||
|
||||
attribute.setBaseValue(newSpeed);
|
||||
commandSender.sendRichMessage(Messages.GHAST_SPEED.NEW_SPEED_SET_TO,
|
||||
Placeholder.parsed("speed", ghastSpeed.name().toLowerCase().replace("_", " ")));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ghastspeed";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabComplete(CommandSender commandSender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return Arrays.stream(GHAST_SPEED.values())
|
||||
.map(GHAST_SPEED::name)
|
||||
.filter(name -> commandSender.hasPermission(
|
||||
getPermission() + "." + name.toLowerCase())).toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpMessage() {
|
||||
return Messages.HELP.GHAST_SPEED;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package com.alttd.playerutils.commands.playerutils_subcommands;
|
|||
|
||||
import com.alttd.playerutils.commands.SubCommand;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
|
@ -19,13 +19,7 @@ import java.util.List;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Glow extends SubCommand {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public Glow(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
@Slf4j public class Glow extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
|
|
@ -106,7 +100,7 @@ public class Glow extends SubCommand {
|
|||
private void turnOnGlow(CommandSender commandSender, Player player, Team team, DyeColor dyeColor, boolean otherPlayer) {
|
||||
if (team.getScoreboard() == null) {
|
||||
commandSender.sendRichMessage(Messages.GLOW.UNABLE_TO_GET_SCOREBOARD);
|
||||
logger.warning("Unable to get scoreboard for team");
|
||||
log.warn("Unable to get scoreboard for team");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ import com.alttd.playerutils.commands.SubCommand;
|
|||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.config.KeyStorage;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -15,13 +15,7 @@ import org.bukkit.entity.Player;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Key extends SubCommand {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public Key(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
@Slf4j public class Key extends SubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender commandSender, String[] args) {
|
||||
|
|
@ -52,7 +46,7 @@ public class Key extends SubCommand {
|
|||
}
|
||||
|
||||
crateMap.addTo(uuid, 1);
|
||||
logger.info(String.format("Gave %s one key for %s", player.getName(), crate));
|
||||
log.info("Gave {} one key for {}", player.getName(), crate);
|
||||
commandSender.getServer().dispatchCommand(Bukkit.getConsoleSender(), String.format("crate give v %s 1 %s", crate, player.getName()));
|
||||
if (keys + 1 == totalKeys) {
|
||||
commandSender.sendRichMessage(Messages.KEY.GAVE_FINAL_KEY, TagResolver.resolver(
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public class XPCheque extends SubCommand {
|
|||
return true;
|
||||
}
|
||||
|
||||
int totalExperience = player.getTotalExperience();
|
||||
int totalExperience = player.calculateTotalExperiencePoints();
|
||||
if (totalExperience < (xpValue * amount)) {
|
||||
commandSender.sendRichMessage(Messages.XP_CHEQUE.NOT_ENOUGH_XP, Placeholder.parsed("xp", String.valueOf(totalExperience)));
|
||||
return true;
|
||||
|
|
@ -139,7 +139,7 @@ public class XPCheque extends SubCommand {
|
|||
}
|
||||
|
||||
public void decreaseExperience(Player player, int xpToRemove) {
|
||||
int totalExp = player.getTotalExperience();
|
||||
int totalExp = player.calculateTotalExperiencePoints();
|
||||
int newTotalExp = Math.max(totalExp - xpToRemove, 0);
|
||||
|
||||
int level = 0;
|
||||
|
|
@ -153,7 +153,7 @@ public class XPCheque extends SubCommand {
|
|||
|
||||
float progress = (float) newTotalExp / getExpToNext(level);
|
||||
|
||||
player.setTotalExperience(totalExp - xpToRemove);
|
||||
player.setExperienceLevelAndProgress(totalExp - xpToRemove);
|
||||
player.setLevel(level);
|
||||
player.setExp(progress);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
|
@ -19,19 +19,16 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"unused", "SameParameterValue"})
|
||||
@Slf4j @SuppressWarnings({"unused", "SameParameterValue"})
|
||||
abstract class AbstractConfig {
|
||||
File file;
|
||||
YamlConfiguration yaml;
|
||||
private static Logger logger = null;
|
||||
|
||||
AbstractConfig(PlayerUtils playerUtils, String filename, Logger logger) {
|
||||
AbstractConfig.logger = logger;
|
||||
AbstractConfig(PlayerUtils playerUtils, String filename) {
|
||||
init(new File(playerUtils.getDataFolder(), filename), filename);
|
||||
}
|
||||
|
||||
AbstractConfig(File file, String filename, Logger logger) {
|
||||
AbstractConfig.logger = logger;
|
||||
AbstractConfig(File file, String filename) {
|
||||
init(new File(file.getPath() + File.separator + filename), filename);
|
||||
}
|
||||
|
||||
|
|
@ -41,10 +38,9 @@ abstract class AbstractConfig {
|
|||
try {
|
||||
yaml.load(file);
|
||||
} catch (IOException ignore) {
|
||||
} catch (InvalidConfigurationException ex) {
|
||||
if (logger != null)
|
||||
logger.severe(String.format("Could not load %s, please correct your syntax errors", filename));
|
||||
throw new RuntimeException(ex);
|
||||
} catch (InvalidConfigurationException e) {
|
||||
log.error("Could not load {}, please correct your syntax errors", filename, e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
yaml.options().copyDefaults(true);
|
||||
}
|
||||
|
|
@ -59,10 +55,8 @@ abstract class AbstractConfig {
|
|||
method.invoke(instance);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new RuntimeException(ex.getCause());
|
||||
} catch (Exception ex) {
|
||||
if (logger != null)
|
||||
logger.severe("Error invoking %.", method.toString());
|
||||
ex.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
log.error("Error invoking {}.", method, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -75,10 +69,8 @@ abstract class AbstractConfig {
|
|||
private void save() {
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException ex) {
|
||||
if (logger != null)
|
||||
logger.severe("Could not save %.", file.toString());
|
||||
ex.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
log.error("Could not save {}.", file.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,4 +142,4 @@ abstract class AbstractConfig {
|
|||
ConfigurationSection getConfigurationSection(String path) {
|
||||
return yaml.getConfigurationSection(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,28 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class Config extends AbstractConfig{
|
||||
@Slf4j public class Config extends AbstractConfig{
|
||||
|
||||
static Config config;
|
||||
private Logger logger;
|
||||
|
||||
Config(Logger logger) {
|
||||
Config() {
|
||||
super(
|
||||
new File(File.separator
|
||||
+ "mnt" + File.separator
|
||||
+ "configs" + File.separator
|
||||
+ "PlayerUtils"),
|
||||
"config.yml", logger);
|
||||
this.logger = logger;
|
||||
"config.yml");
|
||||
}
|
||||
|
||||
public static void reload(Logger logger) {
|
||||
logger.info("Reloading config");
|
||||
config = new Config(logger);
|
||||
public static void reload() {
|
||||
log.info("Reloading config");
|
||||
config = new Config();
|
||||
config.readConfig(Config.class, null);
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +47,7 @@ public class Config extends AbstractConfig{
|
|||
CRATES.clear();
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
||||
if (configurationSection == null) {
|
||||
config.logger.warning("No keys configured, adding default");
|
||||
log.warn("No keys configured, adding default");
|
||||
config.set(prefix, "dailyvotecrate", 0);
|
||||
config.set(prefix, "weeklyvotecrate", 0);
|
||||
config.set(prefix, "questcrate", 0);
|
||||
|
|
@ -73,7 +70,7 @@ public class Config extends AbstractConfig{
|
|||
LIMIT.clear();
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix.substring(0, prefix.length() - 1));
|
||||
if (configurationSection == null) {
|
||||
config.logger.warning("No limits configured, adding default");
|
||||
log.warn("No limits configured, adding default");
|
||||
config.set(prefix, "default", 10);
|
||||
}
|
||||
Set<String> limits = configurationSection.getKeys(false);
|
||||
|
|
@ -82,4 +79,17 @@ public class Config extends AbstractConfig{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LOCATOR_BAR {
|
||||
private static final String prefix = "locator_bar.";
|
||||
|
||||
public static double WAYPOINT_RECEIVE_RANGE = 200;
|
||||
public static double WAYPOINT_TRANSMIT_RANGE = 200;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
WAYPOINT_RECEIVE_RANGE = config.getDouble(prefix, "waypoint_receive_range", WAYPOINT_RECEIVE_RANGE);
|
||||
WAYPOINT_TRANSMIT_RANGE = config.getDouble(prefix, "waypoint_transmit_range", WAYPOINT_TRANSMIT_RANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -9,24 +9,23 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class KeyStorage extends AbstractConfig {
|
||||
|
||||
static KeyStorage config;
|
||||
private final Logger logger;
|
||||
|
||||
public KeyStorage(Logger logger) {
|
||||
public KeyStorage() {
|
||||
super(
|
||||
new File(File.separator
|
||||
+ "mnt" + File.separator
|
||||
+ "configs" + File.separator
|
||||
+ "PlayerUtils"),
|
||||
"key_storage.yml", logger);
|
||||
this.logger = logger;
|
||||
"key_storage.yml");
|
||||
}
|
||||
|
||||
public static void reload(Logger logger) {
|
||||
logger.info("Reloading key storage");
|
||||
config = new KeyStorage(logger);
|
||||
public static void reload() {
|
||||
log.info("Reloading key storage");
|
||||
config = new KeyStorage();
|
||||
config.readConfig(KeyStorage.class, null);
|
||||
}
|
||||
|
||||
|
|
@ -43,13 +42,13 @@ public class KeyStorage extends AbstractConfig {
|
|||
Object2IntOpenHashMap<UUID> count = new Object2IntOpenHashMap<>();
|
||||
ConfigurationSection configurationSection = config.getConfigurationSection(prefix + crate);
|
||||
if (configurationSection == null) {
|
||||
config.logger.info(String.format("No section yet for crate %s", crate));
|
||||
log.info("No section yet for crate {}", crate);
|
||||
KEYS.put(crate, count);
|
||||
continue;
|
||||
}
|
||||
List<UUID> uuids = configurationSection.getKeys(false).stream().map(UUID::fromString).toList();
|
||||
if (uuids.isEmpty()) {
|
||||
config.logger.info(String.format("No keys yet for crate %s", crate));
|
||||
log.info("No keys yet for crate {}", crate);
|
||||
KEYS.put(crate, count);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -62,7 +61,7 @@ public class KeyStorage extends AbstractConfig {
|
|||
}
|
||||
|
||||
public synchronized static void save() {
|
||||
config.logger.info("Saving KeyStorage");
|
||||
log.info("Saving KeyStorage");
|
||||
KEYS.keySet()
|
||||
.forEach(crate -> KEYS.get(crate)
|
||||
.forEach((uuid, keys) -> config.set(prefix + crate + ".", uuid.toString(), keys)));
|
||||
|
|
|
|||
|
|
@ -1,27 +1,22 @@
|
|||
package com.alttd.playerutils.config;
|
||||
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class Messages extends AbstractConfig {
|
||||
static Messages config;
|
||||
private final Logger logger;
|
||||
|
||||
Messages(Logger logger) {
|
||||
Messages() {
|
||||
super(
|
||||
new File(File.separator
|
||||
+ "mnt" + File.separator
|
||||
+ "configs" + File.separator
|
||||
+ "PlayerUtils"),
|
||||
"messages.yml", logger);
|
||||
this.logger = logger;
|
||||
"messages.yml");
|
||||
}
|
||||
|
||||
public static void reload(Logger logger) {
|
||||
config = new Messages(logger);
|
||||
public static void reload() {
|
||||
config = new Messages();
|
||||
config.readConfig(Messages.class, null);
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +31,7 @@ public class Messages extends AbstractConfig {
|
|||
public static String RELOAD = "<green>Reload the configs for PlayerUtils: <gold>/pu reload</gold></green>";
|
||||
public static String ROTATE_BLOCK = "<green>Enable rotating blocks with a blaze rod: <gold>/pu rotateblock</gold></green>";
|
||||
public static String KEY = "<green>Receive a key that you are owed: <gold>/pu key</gold></green>";
|
||||
public static String GHAST_SPEED = "<green>Set the speed of a ghast: <gold>/pu ghastspeed <speed></gold></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
|
|
@ -46,6 +42,7 @@ public class Messages extends AbstractConfig {
|
|||
XP_CALC = config.getString(prefix, "xp-calc", XP_CALC);
|
||||
RELOAD = config.getString(prefix, "reload", RELOAD);
|
||||
ROTATE_BLOCK = config.getString(prefix, "rotate-block", ROTATE_BLOCK);
|
||||
GHAST_SPEED = config.getString(prefix, "ghast-speed", GHAST_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,4 +154,30 @@ public class Messages extends AbstractConfig {
|
|||
GAVE_FINAL_KEY = config.getString(prefix, "gave-final-key", GAVE_FINAL_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GHAST_SPEED {
|
||||
private static final String prefix = "pu-command.ghast-speed.";
|
||||
|
||||
public static String NOT_RIDING_A_GHAST = "<red>You are not riding a ghast</red>";
|
||||
public static String FAILED_TO_SET_SPEED = "<red>Failed to set ghast speed</red>";
|
||||
public static String NEW_SPEED_SET_TO = "<green>New speed set to <speed></green>";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
NOT_RIDING_A_GHAST = config.getString(prefix, "not-riding-a-ghast", NOT_RIDING_A_GHAST);
|
||||
FAILED_TO_SET_SPEED = config.getString(prefix, "failed-to-set-speed", FAILED_TO_SET_SPEED);
|
||||
NEW_SPEED_SET_TO = config.getString(prefix, "new-speed-set-to", NEW_SPEED_SET_TO);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BLOCK_BLOCK_USE {
|
||||
private static final String prefix = "block-block-use.";
|
||||
|
||||
public static String BLOCKED = "<red>You are not powerful enough!</red>";
|
||||
@SuppressWarnings("unused")
|
||||
private static void load() {
|
||||
BLOCKED = config.getString(prefix, "blocked", BLOCKED);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package com.alttd.playerutils.data_objects;
|
||||
|
||||
public enum GHAST_SPEED {
|
||||
SLOW,
|
||||
NORMAL,
|
||||
FAST,
|
||||
VERY_FAST,
|
||||
EXTREMELY_FAST;
|
||||
|
||||
public static double getSpeed(GHAST_SPEED ghastSpeed) {
|
||||
return switch (ghastSpeed) {
|
||||
case SLOW -> 0.025;
|
||||
case NORMAL -> 0.05;
|
||||
case FAST -> 0.075;
|
||||
case VERY_FAST -> 0.1;
|
||||
case EXTREMELY_FAST -> 0.125;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.destroystokyo.paper.MaterialTags;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockCanBuildEvent;
|
||||
import org.bukkit.event.block.BlockDispenseEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class BlockBlockUseEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockCanBuildEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player != null && player.hasPermission("playerutils.block-block-use.bypass")) {
|
||||
return;
|
||||
}
|
||||
if (isNotBlocked(event.getMaterial())) {
|
||||
return;
|
||||
}
|
||||
event.setBuildable(false);
|
||||
if (player != null) {
|
||||
player.sendRichMessage(Messages.BLOCK_BLOCK_USE.BLOCKED);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemUse(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("playerutils.block-block-use.bypass")) {
|
||||
return;
|
||||
}
|
||||
if (!event.getAction().isRightClick()) {
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getItem();
|
||||
if (item == null || isNotBlocked(item.getType())) {
|
||||
return;
|
||||
}
|
||||
player.sendRichMessage(Messages.BLOCK_BLOCK_USE.BLOCKED);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDispenserUse(BlockDispenseEvent event) {
|
||||
if (isNotBlocked(event.getItem().getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public boolean isNotBlocked(Material type) {
|
||||
return !type.equals(Material.BEDROCK)
|
||||
&& !type.equals(Material.SPAWNER)
|
||||
&& !type.equals(Material.BARRIER)
|
||||
&& !type.equals(Material.END_PORTAL_FRAME)
|
||||
&& !MaterialTags.SPAWN_EGGS.isTagged(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.data_objects.GHAST_SPEED;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HappyGhast;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDismountEvent;
|
||||
import org.bukkit.event.entity.EntityMountEvent;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GhastSpeedEvent implements Listener {
|
||||
|
||||
private static final org.slf4j.Logger log = LoggerFactory.getLogger(GhastSpeedEvent.class);
|
||||
|
||||
private final HashMap<UUID, GHAST_SPEED> lastSetSpeed = new HashMap<>();
|
||||
|
||||
public GhastSpeedEvent() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityMount(EntityMountEvent event) {
|
||||
if (!(event.getEntity() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Entity mount = event.getMount();
|
||||
|
||||
if (!(mount instanceof HappyGhast happyGhast)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GHAST_SPEED ghastSpeed = lastSetSpeed.get(player.getUniqueId());
|
||||
if (ghastSpeed == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeInstance attribute = happyGhast.getAttribute(Attribute.FLYING_SPEED);
|
||||
if (attribute == null) {
|
||||
return;
|
||||
}
|
||||
attribute.setBaseValue(GHAST_SPEED.getSpeed(ghastSpeed));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityDismount(EntityDismountEvent event) {
|
||||
if (!(event.getDismounted() instanceof HappyGhast happyGhast)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (happyGhast.getPassengers().size() >= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
AttributeInstance attribute = happyGhast.getAttribute(Attribute.FLYING_SPEED);
|
||||
if (attribute == null) {
|
||||
return;
|
||||
}
|
||||
attribute.setBaseValue(GHAST_SPEED.getSpeed(GHAST_SPEED.NORMAL));
|
||||
}
|
||||
|
||||
public void setNewSpeed(UUID uuid, GHAST_SPEED speed) {
|
||||
lastSetSpeed.put(uuid, speed);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
|
@ -11,13 +11,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GoatHornEvent implements Listener {
|
||||
|
||||
private final Logger logger;
|
||||
|
||||
public GoatHornEvent(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
@Slf4j public class GoatHornEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
|
|
@ -41,11 +35,10 @@ public class GoatHornEvent implements Listener {
|
|||
|
||||
|
||||
if (player.getLocation().distance(spawn) > 250) {
|
||||
logger.info(String.format("Player %s with uuid %s used a goat horn", player.getName(), player.getUniqueId()));
|
||||
log.info("Player {} with uuid {} used a goat horn", player.getName(), player.getUniqueId());
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info(String.format("Player %s with uuid %s used a goat horn in spawn", player.getName(), player.getUniqueId()));
|
||||
log.info("Player {} with uuid {} used a goat horn in spawn", player.getName(), player.getUniqueId());
|
||||
|
||||
player.setCooldown(Material.GOAT_HORN, (int) TimeUnit.MINUTES.toSeconds(5) * 20);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package com.alttd.playerutils.event_listeners;
|
|||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
|
@ -24,14 +24,12 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LimitArmorStands implements Listener {
|
||||
@Slf4j public class LimitArmorStands implements Listener {
|
||||
|
||||
private final PlayerUtils playerUtils;
|
||||
private final Logger logger;
|
||||
|
||||
public LimitArmorStands(PlayerUtils playerUtils, Logger logger) {
|
||||
public LimitArmorStands(PlayerUtils playerUtils) {
|
||||
this.playerUtils = playerUtils;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
|
|
@ -89,7 +87,7 @@ public class LimitArmorStands implements Listener {
|
|||
NamespacedKey namespacedKey = NamespacedKey.fromString("armor_stand_count", playerUtils);
|
||||
if (namespacedKey == null) {
|
||||
event.setCancelled(true);
|
||||
logger.warning("Unable to retrieve name spaced key for armor stand count.");
|
||||
log.warn("Unable to retrieve name spaced key for armor stand count.");
|
||||
player.sendRichMessage("<red>Something went wrong while checking the armor stand count. " +
|
||||
"You will not be able to place this until this is fixed. Please contact a staff member</red>");
|
||||
return;
|
||||
|
|
@ -101,7 +99,7 @@ public class LimitArmorStands implements Listener {
|
|||
Integer armorStandCount = persistentDataContainer.get(namespacedKey, PersistentDataType.INTEGER);
|
||||
if (armorStandCount == null) {
|
||||
event.setCancelled(true);
|
||||
logger.warning("Unable to retrieve armor stand count.");
|
||||
log.warn("Unable to retrieve armor stand count.");
|
||||
player.sendRichMessage("<red>Something went wrong while checking the armor stand count. " +
|
||||
"You will not be able to place this until this is fixed. Please contact a staff member</red>");
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,66 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.config.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@Slf4j
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
|
||||
private final NamespacedKey WAYPOINT_RECEIVE_KEY;
|
||||
private final NamespacedKey WAYPOINT_TRANSMIT_KEY;
|
||||
|
||||
public PlayerJoin(JavaPlugin plugin) {
|
||||
this.WAYPOINT_RECEIVE_KEY = new NamespacedKey(plugin, "waypoint_receive_modifier");
|
||||
this.WAYPOINT_TRANSMIT_KEY = new NamespacedKey(plugin, "waypoint_transmit_modifier");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
setModifiedAttribute(player, Attribute.WAYPOINT_RECEIVE_RANGE, Config.LOCATOR_BAR.WAYPOINT_RECEIVE_RANGE, WAYPOINT_RECEIVE_KEY);
|
||||
setModifiedAttribute(player, Attribute.WAYPOINT_TRANSMIT_RANGE, Config.LOCATOR_BAR.WAYPOINT_TRANSMIT_RANGE, WAYPOINT_TRANSMIT_KEY);
|
||||
}
|
||||
|
||||
private void setModifiedAttribute(Player player, Attribute attribute, double configValue, NamespacedKey key) {
|
||||
AttributeInstance attributeInstance = player.getAttribute(attribute);
|
||||
|
||||
if (attributeInstance == null) {
|
||||
log.error("Unable to retrieve attribute instance for player {}.", player.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
for (AttributeModifier modifier : attributeInstance.getModifiers()) {
|
||||
attributeInstance.removeModifier(modifier);
|
||||
}
|
||||
|
||||
double attributeDelta = configValue - attributeInstance.getBaseValue();
|
||||
|
||||
if (attributeDelta != 0) {
|
||||
AttributeModifier attributeModifier = new AttributeModifier(
|
||||
key,
|
||||
attributeDelta,
|
||||
AttributeModifier.Operation.ADD_NUMBER
|
||||
);
|
||||
|
||||
attributeInstance.addModifier(attributeModifier);
|
||||
}
|
||||
|
||||
double actualValue = attributeInstance.getValue();
|
||||
if (Math.abs(actualValue - configValue) > 0.01) {
|
||||
log.warn("Failed to set attribute {} to {} for {}, actual value is {}.",
|
||||
attribute, configValue, player.getName(), actualValue);
|
||||
} else {
|
||||
log.info("Set attribute {} for {} to {}.", attribute, player.getName(), configValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Axis;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
|
|
@ -21,17 +21,12 @@ import org.bukkit.inventory.ItemStack;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
public class RotateBlockEvent implements Listener {
|
||||
|
||||
private final HashSet<UUID> rotateEnabled = new HashSet<>();
|
||||
private final Logger logger;
|
||||
private static final List<BlockFace> VALID_FOUR_STATES = List.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
|
||||
|
||||
public RotateBlockEvent(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
|
||||
public synchronized boolean toggleRotate(UUID uuid) {
|
||||
if (rotateEnabled.contains(uuid)) {
|
||||
rotateEnabled.remove(uuid);
|
||||
|
|
@ -61,7 +56,8 @@ public class RotateBlockEvent implements Listener {
|
|||
return;
|
||||
|
||||
Material type = block.getType();
|
||||
logger.debug(String.format("Material %s with action %s", type, event.getAction().isLeftClick() ? "left click" : "right click"));
|
||||
log.debug("Material {} with action {}", type, event.getAction().isLeftClick() ? "left " +
|
||||
"click" : "right click");
|
||||
if (type.equals(Material.IRON_TRAPDOOR) && event.getAction().isLeftClick()) {
|
||||
event.setCancelled(true);
|
||||
toggleTrapDoor(block, player);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
package com.alttd.playerutils.event_listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTameEvent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VanillaPetTameEvent implements Listener {
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onEntityTame(EntityTameEvent event) {
|
||||
UUID uniqueId = event.getOwner().getUniqueId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package com.alttd.playerutils.event_listeners;
|
|||
|
||||
import com.alttd.playerutils.PlayerUtils;
|
||||
import com.alttd.playerutils.config.Messages;
|
||||
import com.alttd.playerutils.util.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
|
@ -25,15 +25,13 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class XpBottleEvent implements Listener {
|
||||
@Slf4j public class XpBottleEvent implements Listener {
|
||||
|
||||
private final PlayerUtils playerUtils;
|
||||
private final Logger logger;
|
||||
private final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public XpBottleEvent(PlayerUtils playerUtils, Logger logger) {
|
||||
public XpBottleEvent(PlayerUtils playerUtils) {
|
||||
this.playerUtils = playerUtils;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
@ -42,7 +40,7 @@ public class XpBottleEvent implements Listener {
|
|||
PersistentDataContainer persistentDataContainer = item.getItemMeta().getPersistentDataContainer();
|
||||
NamespacedKey customXp = NamespacedKey.fromString("custom_xp", playerUtils);
|
||||
if (customXp == null) {
|
||||
logger.warning("Unable to retrieve name spaced key.");
|
||||
log.warn("Unable to retrieve name spaced key.");
|
||||
return;
|
||||
}
|
||||
Integer integer = persistentDataContainer.get(customXp, PersistentDataType.INTEGER);
|
||||
|
|
@ -83,7 +81,7 @@ public class XpBottleEvent implements Listener {
|
|||
}
|
||||
|
||||
for (Map.Entry<CookingRecipe<?>, Integer> entry : recipesUsed.entrySet()) {
|
||||
exp += entry.getKey().getExperience() * entry.getValue();
|
||||
exp += (int) (entry.getKey().getExperience() * entry.getValue());
|
||||
}
|
||||
|
||||
Optional<ItemStack> optionalItemStack = getExpBottleItem(player, exp);
|
||||
|
|
|
|||
|
|
@ -1,42 +0,0 @@
|
|||
package com.alttd.playerutils.util;
|
||||
|
||||
import com.alttd.playerutils.config.Config;
|
||||
|
||||
public class Logger {
|
||||
|
||||
private final java.util.logging.Logger logger;
|
||||
static private final String RESET = "\u001B[0m";
|
||||
static private final String GREEN = "\u001B[32m";
|
||||
static private final String TEAL = "\u001B[36m";
|
||||
|
||||
public Logger(java.util.logging.Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void debug(String debug, String... variables) {
|
||||
if (!Config.SETTINGS.DEBUG)
|
||||
return;
|
||||
logger.info(TEAL + replace(debug, variables) + RESET);
|
||||
}
|
||||
|
||||
public void info(String info, String... variables) {
|
||||
logger.info(GREEN + replace(info, variables) + RESET);
|
||||
}
|
||||
|
||||
public void warning(String warning, String... variables) {
|
||||
if (!Config.SETTINGS.WARNINGS)
|
||||
return;
|
||||
logger.warning(replace(warning, variables));
|
||||
}
|
||||
|
||||
public void severe(String severe, String... variables) {
|
||||
logger.severe(replace(severe, variables));
|
||||
}
|
||||
|
||||
private String replace(String text, String... variables) {
|
||||
for (String variable : variables) {
|
||||
text = text.replaceFirst("%", variable);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user