Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit b2eb54c

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 42b9853 + d660616 commit b2eb54c

File tree

6 files changed

+345
-8
lines changed

6 files changed

+345
-8
lines changed

src/main/java/fr/communaywen/core/AywenCraftPlugin.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
import fr.communaywen.core.contest.listeners.*;
3737
import fr.communaywen.core.customitems.listeners.*;
38+
import fr.communaywen.core.event.CubeListener;
39+
import fr.communaywen.core.event.CubeManager;
3840
import fr.communaywen.core.listeners.*;
3941

4042
import fr.communaywen.core.contest.managers.ContestManager;
@@ -375,6 +377,7 @@ public void run() {
375377

376378
/* LISTENERS */
377379
registerEvents(
380+
new CubeListener(),
378381
new ParticleListener(this),
379382
new HeadListener(this),
380383
new JumpListener(this, jumpManager),
@@ -440,8 +443,7 @@ public void run() {
440443
QuestsManager.initializeQuestsTable();
441444
ClaimConfigDataBase.processStoredClaimData();
442445
new BandageRecipe();
443-
444-
446+
new CubeManager(this);
445447
// BETTER SPAWN
446448
// - Leaderboard
447449
LeaderboardManager.createLeaderboardBalTop();
@@ -480,7 +482,8 @@ public void onDisable() {
480482

481483
jumpManager.removeDisplayJumpStart();
482484
jumpManager.removeDisplayJumpEnd();
483-
485+
CubeManager.saveCubeLocation();
486+
CubeManager.clearCube();
484487
for (Player player : Bukkit.getOnlinePlayers()) {
485488
PlayerQuests pq = QuestsManager.getPlayerQuests(player.getUniqueId()); // Load quest progress
486489
QuestsManager.savePlayerQuestProgress(player, pq); // Save quest progress

src/main/java/fr/communaywen/core/Managers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public class Managers {
8484
private FileConfiguration levelsConfig;
8585
private FileConfiguration quizzesConfig;
8686
private FileConfiguration customItemsConfig;
87+
private FileConfiguration kevinConfig;
8788

8889
public void initConfig(AywenCraftPlugin plugin) {
8990
plugin.saveDefaultConfig();
@@ -93,6 +94,7 @@ public void initConfig(AywenCraftPlugin plugin) {
9394
levelsConfig = ConfigUtils.loadConfig(plugin, "levels.yml");
9495
quizzesConfig = ConfigUtils.loadConfig(plugin, "quizzes.yml");
9596
customItemsConfig = ConfigUtils.loadConfig(plugin, "customitems.yml");
97+
kevinConfig = ConfigUtils.loadConfig(plugin, "cube.yml");
9698
}
9799

98100
public void init(AywenCraftPlugin plugin) {

src/main/java/fr/communaywen/core/contest/managers/ContestManager.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void initPhase3(JavaPlugin plugin, FileConfiguration eventConfig) {
312312
String playerCampName = getOfflinePlayerCampName(player);
313313
ChatColor playerCampColor = ColorConvertor.getReadableColor(getOfflinePlayerCampChatColor(player));
314314

315-
bookMetaPlayer.addPage("§8§lStatistiques Personnelles\n§0Votre camp : " + playerCampColor + playerCampName + "\n§0Votre Grade sur Le Contest §8: " + playerCampColor + getRankContestFroOffline(player) + playerCampName + "\n§0Votre Rang sur Le Contest : §8#" + getRankPlayerInContest(player) + "\n§0Points Déposés : §b" + rs1.getString("point_dep"));
315+
bookMetaPlayer.addPage("§8§lStatistiques Personnelles\n§0Votre camp : " + playerCampColor + playerCampName + "\n§0Votre Grade sur Le Contest §8: " + playerCampColor + getRankContestFroOffline(player) + playerCampName + "\n§0Votre Rang sur Le Contest : §8#" + getRankPlayerInContest(rs1.getInt("point_dep")) + "\n§0Points Déposés : §b" + rs1.getString("point_dep"));
316316

317317
int money = 0;
318318
int lucky = 0;
@@ -507,7 +507,7 @@ public static String getTimeUntilNextMonday() {
507507
public Integer getPlayerPoints(Player player) {
508508
UUID playerUUID = player.getUniqueId();
509509

510-
String sql = "SELECT * FROM camps WHERE minecraft_uuid = ?";
510+
String sql = "SELECT * FROM camps WHERE minecraft_uuid = ? LIMIT 1";
511511
try (PreparedStatement states = connection.prepareStatement(sql)) {
512512
states.setString(1, playerUUID.toString());
513513
ResultSet result = states.executeQuery();
@@ -639,10 +639,10 @@ public ChatColor getOfflinePlayerCampChatColor(OfflinePlayer player) {
639639
return campColor;
640640
}
641641

642-
public Integer getRankPlayerInContest(OfflinePlayer player) {
643-
String sql = "SELECT COUNT(*) AS rank FROM camps WHERE point_dep > (SELECT point_dep FROM camps WHERE minecraft_uuid = ?);";
642+
public Integer getRankPlayerInContest(Integer pointsDep) {
643+
String sql = "SELECT COUNT(*) AS rank FROM camps WHERE point_dep > ?";
644644
try (PreparedStatement states = connection.prepareStatement(sql)) {
645-
states.setString(1, player.getUniqueId().toString());
645+
states.setInt(1, pointsDep);
646646
ResultSet result = states.executeQuery();
647647
if (result.next()) {
648648
return result.getInt("rank") + 1;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package fr.communaywen.core.event;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.Sound;
5+
import org.bukkit.entity.Player;
6+
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.Listener;
8+
import org.bukkit.event.block.BlockBreakEvent;
9+
import org.bukkit.event.entity.EntityDamageByEntityEvent;
10+
import org.bukkit.event.player.PlayerInteractEvent;
11+
import org.bukkit.event.player.PlayerMoveEvent;
12+
import org.bukkit.util.Vector;
13+
14+
import static fr.communaywen.core.event.CubeManager.*;
15+
16+
public class CubeListener implements Listener {
17+
@EventHandler
18+
public void onPlayerInteract(PlayerInteractEvent event) {
19+
Location clickedBlock = event.getClickedBlock() != null ? event.getClickedBlock().getLocation() : null;
20+
if (clickedBlock != null && isCubeBlock(clickedBlock)) {
21+
repulsePlayer(event.getPlayer());
22+
}
23+
}
24+
25+
@EventHandler
26+
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
27+
if (event.getDamager() instanceof Player player && isCubeBlock(event.getEntity().getLocation())) {
28+
repulsePlayer(player);
29+
}
30+
}
31+
32+
@EventHandler
33+
public void onBlockBreak(BlockBreakEvent event) {
34+
if (isCubeBlock(event.getBlock().getLocation())) {
35+
event.setCancelled(true);
36+
}
37+
}
38+
39+
@EventHandler
40+
public void onPlayerMove(PlayerMoveEvent event) {
41+
Player player = event.getPlayer();
42+
Location belowPlayer = player.getLocation().clone().subtract(0, 1, 0);
43+
44+
if (isCubeBlock(belowPlayer)) {
45+
Vector velocity = player.getVelocity();
46+
velocity.setY(1.0);
47+
player.setVelocity(velocity);
48+
49+
player.playSound(player.getLocation(), Sound.BLOCK_BEACON_POWER_SELECT, 1.0f, 2.0f);
50+
}
51+
}
52+
53+
54+
public static boolean isCubeBlock(Location blockLocation) {
55+
int x = blockLocation.getBlockX();
56+
int y = blockLocation.getBlockY();
57+
int z = blockLocation.getBlockZ();
58+
59+
int cubeX = currentLocation.getBlockX();
60+
int cubeY = currentLocation.getBlockY();
61+
int cubeZ = currentLocation.getBlockZ();
62+
63+
return x >= cubeX && x < cubeX + CUBE_SIZE &&
64+
y >= cubeY && y < cubeY + CUBE_SIZE &&
65+
z >= cubeZ && z < cubeZ + CUBE_SIZE &&
66+
blockLocation.getBlock().getType() == CUBE_MATERIAL;
67+
}
68+
69+
private void repulsePlayer(Player player) {
70+
Vector direction = player.getLocation().toVector().subtract(currentLocation.toVector()).normalize();
71+
direction.multiply(3);
72+
direction.setY(1);
73+
player.setVelocity(direction);
74+
75+
player.playSound(player.getLocation(), Sound.BLOCK_BEACON_POWER_SELECT, 1.0f, 2.0f);
76+
}
77+
}

0 commit comments

Comments
 (0)