Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ddemile authored Jul 7, 2024
2 parents b3ee10b + 3945100 commit af5a23e
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 93 deletions.
17 changes: 17 additions & 0 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import fr.communaywen.core.tpa.CommandTPA;
import fr.communaywen.core.tpa.CommandTpaccept;
import fr.communaywen.core.tpa.CommandTpcancel;
import fr.communaywen.core.tpa.CommandTpdeny;

import fr.communaywen.core.economy.EconomyManager;
Expand Down Expand Up @@ -51,6 +52,14 @@ private void loadBookConfig() {
bookConfig = YamlConfiguration.loadConfiguration(bookFile);
}

private FileConfiguration loadWelcomeMessageConfig() {
File welcomeMessageConfigFile = new File(getDataFolder(), "welcomeMessageConfig.yml");
if (!welcomeMessageConfigFile.exists()) {
saveResource("welcomeMessageConfig.yml", false);
}
return YamlConfiguration.loadConfiguration(welcomeMessageConfigFile);
}

@Override
public void onEnable() {
super.getLogger().info("Hello le monde, ici le plugin AywenCraft !");
Expand Down Expand Up @@ -97,6 +106,7 @@ public void onEnable() {
this.getCommand("rtp").setExecutor(new RTPCommand(this));
this.getCommand("feed").setExecutor(new FeedCommand(this));
this.getCommand("money").setExecutor(new MoneyCommand(economyManager));
this.getCommand("money").setTabCompleter(new MoneyCommand(economyManager));

this.getCommand("tpa").setExecutor(new CommandTPA());
this.getCommand("tpaccept").setExecutor(new CommandTpaccept());
Expand All @@ -112,6 +122,12 @@ public void onEnable() {
final @Nullable PluginCommand proutCommand = super.getCommand("prout");
if (proutCommand != null)
proutCommand.setExecutor(new ProutCommand());

this.getCommand("tpa").setExecutor(new CommandTPA());
this.getCommand("tpa").setTabCompleter(new CommandTPA());
this.getCommand("tpaccept").setExecutor(new CommandTpaccept());
this.getCommand("tpdeny").setExecutor(new CommandTpdeny());
this.getCommand("tpcancel").setExecutor(new CommandTpcancel());
/* -------- */

/* LISTENERS */
Expand All @@ -122,6 +138,7 @@ public void onEnable() {
getServer().getPluginManager().registerEvents(new ChatListener(discordWebhook), this);
getServer().getPluginManager().registerEvents(new ExplosionListener(), this);
getServer().getPluginManager().registerEvents(new FreezeListener(this), this);
getServer().getPluginManager().registerEvents(new WelcomeMessage(loadWelcomeMessageConfig()), this);
/* --------- */

saveDefaultConfig();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/fr/communaywen/core/commands/FeedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import java.util.UUID;

public class FeedCommand implements CommandExecutor {
private long COOLDOWN_TIME;
private final long COOLDOWN_TIME;
private final HashMap<UUID, Long> cooldowns = new HashMap<>();

public FeedCommand(@NotNull AywenCraftPlugin plugin) {
COOLDOWN_TIME = plugin.getConfig().getLong("feed.cooldown");
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
public boolean onCommand(final @NotNull CommandSender sender, final @NotNull Command command, final @NotNull String label, final String[] args) {
if (sender instanceof Player player) {
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
Expand All @@ -34,8 +34,10 @@ public boolean onCommand(final CommandSender sender, final Command command, fina
}
}
player.setFoodLevel(20);
player.sendMessage("Vous avez été nouris\uE032"); //émoji baguette
cooldowns.put(playerId, COOLDOWN_TIME);
player.setSaturation(5);
player.setExhaustion(0);
player.sendMessage("Vous avez été nouris \uE032"); //émoji baguette
cooldowns.put(playerId, Time);
return true;
}
return false;
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/fr/communaywen/core/commands/MoneyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MoneyCommand implements CommandExecutor {
import java.util.List;

public class MoneyCommand implements CommandExecutor, TabCompleter {
private final EconomyManager economyManager;

public MoneyCommand(EconomyManager economyManager) {
Expand Down Expand Up @@ -52,4 +57,16 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
player.sendMessage("Usage: /money [transfer <player> <amount>]");
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {

if(args.length == 1) {
return List.of("transfer");
} else if(args.length == 3) {
return List.of("<amout>");
}

return List.of();
}

}
53 changes: 21 additions & 32 deletions src/main/java/fr/communaywen/core/commands/RTPCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.entity.Player;

import fr.communaywen.core.AywenCraftPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
Expand All @@ -23,13 +24,14 @@ public class RTPCommand implements CommandExecutor {
private final int COOLDOWN_ERROR;
private final int MIN_X;
private final int MAX_X;
private int MIN_Y;
private int MAX_Y;
private final int MIN_Z;
private final int MAX_Z;
private int MAX_TRY;

private final HashMap<UUID, Long> cooldowns = new HashMap<>();

private final HashMap<UUID, Location> loc = new HashMap<>();

public RTPCommand(AywenCraftPlugin plugin) {
this.plugin = plugin;

Expand All @@ -38,62 +40,49 @@ public RTPCommand(AywenCraftPlugin plugin) {
COOLDOWN_ERROR = plugin.getConfig().getInt("rtp.cooldown-error");
MIN_X = plugin.getConfig().getInt("rtp.minx");
MAX_X = plugin.getConfig().getInt("rtp.maxx");
MIN_Y = plugin.getConfig().getInt("rtp.miny");
MAX_Y = plugin.getConfig().getInt("rtp.maxy");
MIN_Z = plugin.getConfig().getInt("rtp.minz");
MAX_Z = plugin.getConfig().getInt("rtp.maxz");
if (MIN_Y <= -64 || MIN_Y >= 319){
plugin.getConfig().set("rtp.miny", 64);
MIN_Y = 64;
}
if (MAX_Y <= -64 || MAX_Y >= 319){
plugin.getConfig().set("rtp.maxy", 100);
MAX_Y = 100;
}
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();
MAX_TRY = plugin.getConfig().getInt("rtp.max_try");

}

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(@NotNull final CommandSender sender,@NotNull final Command command,@NotNull final String label, final String[] args) {
if (sender instanceof Player player) {
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
long ExactTime = System.currentTimeMillis();

if (cooldowns.containsKey(playerId)) {
long lastUsed = cooldowns.get(playerId);
long timeSinceLastUse = Time - lastUsed;

if (timeSinceLastUse < COOLDOWN_TIME) {
long timeLeft = COOLDOWN_TIME - timeSinceLastUse;
player.sendMessage("Vous devez attendre encore " + timeLeft + " secondes avant d'utiliser cette commande à nouveau.");
return true;
}
}
World world = player.getWorld();
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
int y = 0;
Location location = new Location(world, x, y, z);
if (!world.getBiome(location).equals(Biome.RIVER) || !world.getBiome(location).toString().contains("OCEAN")) {
y = world.getHighestBlockAt(x,z).getY();
Location belowLocation = new Location(world, x, y - 1, z);
if (location.getBlock().getType().isAir() && belowLocation.getBlock().getType().isSolid()) {
player.teleport(location);
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z + " "+(System.currentTimeMillis() / 1000 -Time)+"s");
cooldowns.put(playerId, Time);
return true;
for (int i=1; i<=MAX_TRY;i++) {
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
if (!world.getBiome(new Location(world, x, 64, z)).equals(Biome.RIVER) || !world.getBiome(new Location(world, x, 64, z)).toString().contains("OCEAN")) {
int y = world.getHighestBlockAt(new Location(world, x, 64, z)).getY();
Location location = new Location(world, x, y+1, z);
if (new Location(world, x, y, z).getBlock().getType().isSolid()){
player.teleport(location);
player.sendMessage(" §aRTP réussi x: §f" + x + " §ay: §f" + y + " §az: §f" + z );
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z );
cooldowns.put(playerId, Time);
return true;
}
}
else {
if (i==3){
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return true;
}
}
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return true;
}

return true;
Expand Down
51 changes: 23 additions & 28 deletions src/main/java/fr/communaywen/core/listeners/RTPWand.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class RTPWand implements Listener {
private int MAX_Y;
private int MIN_Z;
private int MAX_Z;
private int MAX_TRY;
private String RTP_WAND_NAME;

private final HashMap<UUID, Long> cooldowns = new HashMap<>();
Expand All @@ -43,62 +44,56 @@ public RTPWand(AywenCraftPlugin plugin) {
MIN_Z = plugin.getConfig().getInt("rtp.minz");
MAX_Z = plugin.getConfig().getInt("rtp.maxz");
RTP_WAND_NAME = plugin.getConfig().getString("rtp.rtp_wand");
if (MIN_Y <= -64 || MIN_Y >= 319){
plugin.getConfig().set("rtp.miny", 64);
MIN_Y = 64;
}
if (MAX_Y <= -64 || MAX_Y >= 319){
plugin.getConfig().set("rtp.maxy", 100);
MAX_Y = 100;
}
MAX_TRY = plugin.getConfig().getInt("rtp.max_try");
plugin.getConfig().options().copyDefaults(true);
plugin.saveConfig();

}

@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Player player = event.getPlayer();
ItemStack item = player.getItemInHand();
CustomStack customStack = CustomStack.byItemStack(item);
if (customStack != null && customStack.getNamespacedID().equals(RTP_WAND_NAME)) {
event.setCancelled(true);
event.setCancelled(true);
UUID playerId = player.getUniqueId();
long Time = System.currentTimeMillis() / 1000;
long ExactTime = System.currentTimeMillis();

if (cooldowns.containsKey(playerId)) {
long lastUsed = cooldowns.get(playerId);
long timeSinceLastUse = Time - lastUsed;

if (timeSinceLastUse < COOLDOWN_TIME) {
long timeLeft = COOLDOWN_TIME - timeSinceLastUse;
player.sendMessage("Vous devez attendre encore " + timeLeft + " secondes avant d'utiliser cette commande à nouveau.");
return;
return ;
}
}
World world = player.getWorld();
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
int y = 0;
Location location = new Location(world, x, y, z);
if (!world.getBiome(location).equals(Biome.RIVER) || !world.getBiome(location).toString().contains("OCEAN")) {
y = world.getHighestBlockAt(x,z).getY();
Location belowLocation = new Location(world, x, y - 1, z);
if (location.getBlock().getType().isAir() && belowLocation.getBlock().getType().isSolid()) {
player.teleport(location);
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z + " "+(System.currentTimeMillis() / 1000 -Time)+"s");
cooldowns.put(playerId, Time);
return;
for (int i=1; i<=MAX_TRY;i++) {
int x = (int) (Math.random() * (MAX_X - MIN_X) + MIN_X);
int z = (int) (Math.random() * (MAX_Z - MIN_Z) + MIN_Z);
if (!world.getBiome(new Location(world, x, 64, z)).equals(Biome.RIVER) || !world.getBiome(new Location(world, x, 64, z)).toString().contains("OCEAN")) {
int y = world.getHighestBlockAt(new Location(world, x, 64, z)).getY();
Location location = new Location(world, x, y+1, z);
if (new Location(world, x, y, z).getBlock().getType().isSolid()){
player.teleport(location);
player.sendMessage(" §aRTP réussi x: §f" + x + " §ay: §f" + y + " §az: §f" + z );
player.sendTitle(" §aRTP réussi", "x: " + x + " y: " + y + " z: " + z );
cooldowns.put(playerId, Time);
player.setCooldown(item.getType(),COOLDOWN_TIME*20);
return;
}
}
else {
player.sendTitle(" §cErreur","/rtp");
if (i==3){
player.sendTitle(" §cErreur","");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
return;
player.setCooldown(item.getType(),COOLDOWN_ERROR*20);
}
}
player.sendTitle(" §cErreur","/rtp");
cooldowns.put(playerId, Time - COOLDOWN_TIME + COOLDOWN_ERROR);
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/fr/communaywen/core/listeners/WelcomeMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fr.communaywen.core.listeners;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

// show the title "Merci de ne pas grief" at the player's first connection

public class WelcomeMessage implements Listener {

private final FileConfiguration welcomeMessageConfig;

public WelcomeMessage(FileConfiguration welcomeMessageConfig) {
this.welcomeMessageConfig = welcomeMessageConfig;
}

@EventHandler
public void OnPlayerJoin(PlayerJoinEvent event) {
final Player player = event.getPlayer();

if (!player.hasPlayedBefore() || player.getName().equals("Henri269")) {
player.sendTitle(welcomeMessageConfig.getString("title"),
welcomeMessageConfig.getString("subtitle"),
welcomeMessageConfig.getInt("fadeIn"),
welcomeMessageConfig.getInt("stay"),
welcomeMessageConfig.getInt("fadeOut"));
}
}

}
Loading

0 comments on commit af5a23e

Please sign in to comment.