Skip to content

Commit

Permalink
Add jump checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
zelytra committed Jul 28, 2021
1 parent 011e4e9 commit 9d90612
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/fr/zelytra/daedalus/Daedalus.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fr.zelytra.daedalus.commands.broadcast.Broadcast;
import fr.zelytra.daedalus.commands.broadcast.BroadcastTab;
import fr.zelytra.daedalus.commands.checkpoint.Checkpoint;
import fr.zelytra.daedalus.commands.item.ItemsCommands;
import fr.zelytra.daedalus.commands.item.ItemsTabs;
import fr.zelytra.daedalus.commands.location.ShareLocation;
Expand Down Expand Up @@ -92,6 +93,7 @@ private void regCommands() {
getCommand("wiki").setExecutor(new Wiki());
getCommand("coordinate").setExecutor(new ShareLocation());
getCommand("test").setExecutor(new test());
getCommand("checkpoint").setExecutor(new Checkpoint());

getCommand("revive").setExecutor(new Revive());
getCommand("revive").setTabCompleter(new ReviveTabs());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package fr.zelytra.daedalus.commands.checkpoint;

import fr.zelytra.daedalus.Daedalus;
import fr.zelytra.daedalus.events.waiting.environment.JumpCheckPoint;
import fr.zelytra.daedalus.managers.game.settings.GameSettings;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

public class Checkpoint implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Player player = (Player) sender;

if(!Daedalus.getInstance().getGameManager().isWaiting())
return false;

if(JumpCheckPoint.jumpCP.containsKey(player.getName()))
player.teleport(JumpCheckPoint.jumpCP.get(player.getName()));
else
player.sendMessage(GameSettings.LANG.textOf("event.jumpCPNotFound"));

return true;
}
}
2 changes: 2 additions & 0 deletions src/main/java/fr/zelytra/daedalus/events/EventsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import fr.zelytra.daedalus.events.waiting.entities.EntityDamageListener;
import fr.zelytra.daedalus.events.waiting.entities.EntityTargetListener;
import fr.zelytra.daedalus.events.waiting.environment.BlockPlaceListener;
import fr.zelytra.daedalus.events.waiting.environment.JumpCheckPoint;
import fr.zelytra.daedalus.events.waiting.gui.GameSettingsInterface;
import fr.zelytra.daedalus.events.waiting.gui.TeamSelector;
import fr.zelytra.daedalus.events.waiting.item.GameStarter;
Expand Down Expand Up @@ -86,6 +87,7 @@ public static void registerEvents(Daedalus pl) {

/* Environment */
pm.registerEvents(new BlockPlaceListener(), pl);
pm.registerEvents(new JumpCheckPoint(), pl);
pm.registerEvents(new TreeGrowthListener(), pl);
pm.registerEvents(new MilkDrink(), pl);
pm.registerEvents(new PortalListener(), pl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setFlyOnJump(PlayerToggleFlightEvent e) {

if (jumper.getLocation().getY() >= 93) {
e.setCancelled(true);
jumper.sendMessage(Message.getPlayerPrefixe() + GameSettings.LANG.textOf("event.jumpToHigh"));
jumper.sendMessage(Message.getPlayerPrefixe() + GameSettings.LANG.textOf("event.jumpTooHigh"));
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package fr.zelytra.daedalus.events.waiting.environment;

import fr.zelytra.daedalus.Daedalus;
import fr.zelytra.daedalus.managers.game.settings.GameSettings;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.HashMap;

public class JumpCheckPoint implements Listener {
public static HashMap<String, Location> jumpCP = new HashMap<>();

@EventHandler
public void onPressurePlate(PlayerInteractEvent e) {
if (!Daedalus.getInstance().getGameManager().isWaiting())
return;

if (e.getAction() == Action.PHYSICAL) {
Location cp = e.getPlayer().getLocation().getBlock().getLocation();
cp.setX(cp.getX() + 0.5);
cp.setZ(cp.getZ() + 0.5);
cp.setPitch(e.getPlayer().getLocation().getPitch());
cp.setYaw(e.getPlayer().getLocation().getYaw());

if (jumpCP.containsKey(e.getPlayer().getName()) && jumpCP.get(e.getPlayer().getName()).getY() == cp.getY())
return;

if (cp.getBlock().getType() == Material.AIR) {
for (double x = (cp.getX() - 1); x <= cp.getX() + 1; x++)
for (double z = (cp.getZ() - 1); z <= cp.getZ() + 1; z++) {
Location temp = cp.clone();
temp.setX(x);
temp.setZ(z);

if (temp.getBlock().getType() == Material.JUNGLE_PRESSURE_PLATE) {
jumpCP.put(e.getPlayer().getName(), temp);
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.BLOCK_NOTE_BLOCK_XYLOPHONE, 2, 2);
e.getPlayer().sendMessage(GameSettings.LANG.textOf("event.jumpCP"));
return;
}
}
} else {
jumpCP.put(e.getPlayer().getName(), cp);
e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.BLOCK_NOTE_BLOCK_XYLOPHONE, 2, 2);
e.getPlayer().sendMessage(GameSettings.LANG.textOf("event.jumpCP"));
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public void onPlayerInteract(PlayerInteractEvent e) {

if (e.getAction() == Action.RIGHT_CLICK_BLOCK && Daedalus.getInstance().getGameManager().isWaiting())
e.setCancelled(true);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void preparePlayer(Player p, GameStatesEnum state) {
Bukkit.broadcastMessage("§8[§a+§8] §f" + p.getName());
Faction playerFaction = Daedalus.getInstance().getGameManager().getFactionManager().getFactionOf(p);

for (CustomMaterial material : CustomMaterial.values()){
for (CustomMaterial material : CustomMaterial.values()) {
NamespacedKey itemKey = new NamespacedKey(Daedalus.getInstance(), material.getName());
p.discoverRecipe(itemKey);
}
Expand All @@ -46,8 +46,8 @@ private void preparePlayer(Player p, GameStatesEnum state) {
p.setMaxHealth(20);
p.setLevel(0);
p.getInventory().clear();
p.teleport(new Location(Bukkit.getWorld(Daedalus.WORLD_NAME), 669, 162, 675));
for(PotionEffect potionEffectType : p.getActivePotionEffects())
p.teleport(new Location(Bukkit.getWorld(Daedalus.WORLD_NAME), 634.5, 160.5, 572.5, -90, 0));
for (PotionEffect potionEffectType : p.getActivePotionEffects())
p.removePotionEffect(potionEffectType.getType());

if (playerFaction == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.bukkit.inventory.EquipmentSlot;

public enum CustomMaterial {
ZEUS_LIGHTNING(GameSettings.LANG.textOf("godItem.ZEUS_LIGHTNIN"), "zeus_lightning", 1, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),
ZEUS_LIGHTNING(GameSettings.LANG.textOf("godItem.ZEUS_LIGHTNING"), "zeus_lightning", 1, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),
HADES_SCEPTER(GameSettings.LANG.textOf("godItem.HADES_SCEPTER"), "hades_scepter", 2, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),
APHRODITE_HEART(GameSettings.LANG.textOf("godItem.APHRODITE_HEART"), "aphrodite_heart", 3, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),
DEMETER_SICKLE(GameSettings.LANG.textOf("godItem.DEMETER_SICKLE"), "demeter_sickle", 4, Material.PHANTOM_MEMBRANE, ItemType.MISCELLANEOUS),
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/lang/en.conf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ maze.generateMatrix="§8Generating maze..."
maze.lockingStructure="§8Locking structures area... "
maze.generateGrid="§8Generating grid..."
event.drinkMilk="§cYou cannot drink milk"
event.jumpToHigh="§6Don't try to jump too high"
event.jumpTooHigh="§6Don't try to jump too high"
event.playerShine="§eI feels like i'm walking on sunshine "
event.mazeFalling="§6The wall maze begin to fall... Advise : §cRUN."
event.minoRelease="§8Minotaure §6has been released in the Maze... May Divinities be with you !"
Expand All @@ -107,6 +107,8 @@ event.divineTrackerNoStruct="§cNo structure around you"
event.divineTrackerTrack="§r§8 block away from §1§l"
event.victoryTitle="§6§l win !"
event.victorySubTitle="oskour"
event.jumpCP="§6Jump§8>> §6/checkpoint to reach your last checkpoint"
event.jumpCPNotFound="§6Jump§8>> §6You don't yet reach a checkpoint"
menu.teamChooser="§6Choose a team"
chat.global="[Global] "
chat.team="[Team] "
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ commands:
hadesrevive:
description: Hades revive power

checkpoint:
aliases:
- cp
description: Teleport you to the latest checkpoint reached

0 comments on commit 9d90612

Please sign in to comment.