Skip to content

Commit

Permalink
Merge pull request #261 from TiagoFar78/bugsFixing
Browse files Browse the repository at this point in the history
Fix small bugs
  • Loading branch information
iquelli authored Jun 16, 2024
2 parents c0918a8 + 42ab04a commit 4976d27
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/game/PEGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.tiagofar78.prisonescape.bukkit.BukkitSoundBoard;
import net.tiagofar78.prisonescape.bukkit.BukkitTeleporter;
import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor;
import net.tiagofar78.prisonescape.game.phases.Disabled;
import net.tiagofar78.prisonescape.game.phases.Finished;
import net.tiagofar78.prisonescape.game.phases.Phase;
import net.tiagofar78.prisonescape.game.phases.Waiting;
Expand Down Expand Up @@ -118,6 +119,7 @@ public int playerJoin(String playerName) {

BukkitTeleporter.teleport(player, _prison.getWaitingLobbyLocation());
player.setKit(new TeamSelectorKit());
player.clearEffects();

int maxPlayers = config.getMaxPlayers();
int playerNumber = _playersOnLobby.size();
Expand Down Expand Up @@ -417,6 +419,12 @@ public void run() {
}

private void disableGame() {
if (_phase.isGameDisabled()) {
return;
}

_phase = new Disabled();

for (PEPlayer player : _playersOnLobby) {
teleportToLeavingLocation(player);
player.removeScoreboard();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,17 @@ public void setEffect(PotionEffectType effect, int seconds, int level) {
player.addPotionEffect(new PotionEffect(effect, ticksDuration, level));
}

public void clearEffects() {
Player player = Bukkit.getPlayer(getName());
if (player == null || !player.isOnline()) {
return;
}

for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
}

private void setItemBukkit(int index, Item item) {
Player bukkitPlayer = Bukkit.getPlayer(getName());
if (bukkitPlayer == null || !bukkitPlayer.isOnline()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package net.tiagofar78.prisonescape.game.phases;

public class Disabled extends Phase {

@Override
public Phase next() {
return null;
}

@Override
public boolean isClockStopped() {
return true;
}

@Override
public boolean hasGameStarted() {
return true;
}

@Override
public boolean hasGameEnded() {
return true;
}

@Override
public boolean isGameDisabled() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Finished extends Phase {

@Override
public Phase next() {
return null;
return new Disabled();
}

@Override
Expand All @@ -21,4 +21,9 @@ public boolean hasGameStarted() {
public boolean hasGameEnded() {
return true;
}

@Override
public boolean isGameDisabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public boolean hasGameStarted() {
public boolean hasGameEnded() {
return false;
}

@Override
public boolean isGameDisabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public abstract class Phase {

public abstract boolean hasGameEnded();

public abstract boolean isGameDisabled();

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public boolean hasGameStarted() {
public boolean hasGameEnded() {
return false;
}

@Override
public boolean isGameDisabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ public PrisonBuilding(Location reference) {
_doors = new Hashtable<>();
for (Location loc : config.getGoldenDoorsLocations()) {
Location referenceLoc = loc.add(reference);
GoldenDoor goldenDoor = new GoldenDoor();
GoldenDoor goldenDoor = new GoldenDoor(referenceLoc);
_doors.put(referenceLoc, goldenDoor);
_doors.put(referenceLoc.clone().add(0, 1, 0), goldenDoor);
}
for (Location loc : config.getGrayDoorsLocations()) {
Location referenceLoc = loc.add(reference);
GrayDoor grayDoor = new GrayDoor();
GrayDoor grayDoor = new GrayDoor(referenceLoc);
_doors.put(referenceLoc, grayDoor);
_doors.put(referenceLoc.clone().add(0, 1, 0), grayDoor);
}
for (Location loc : config.getCodeDoorsLocations()) {
Location referenceLoc = loc.add(reference);
CodeDoor codeDoor = new CodeDoor();
CodeDoor codeDoor = new CodeDoor(referenceLoc);
_doors.put(referenceLoc, codeDoor);
_doors.put(referenceLoc.clone().add(0, 1, 0), codeDoor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CellDoor extends Door {
private Location _location;

public CellDoor(Location location) {
super(location);
_location = location;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Location;

public class CodeDoor extends Door {

public CodeDoor() {
super();
public CodeDoor(Location location) {
super(location);
}

public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public abstract class Door {

private boolean _isOpen;

public Door() {
_isOpen = false;
public Door(Location location) {
close(location);
}

public boolean isOpened() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Location;

public class GoldenDoor extends Door {

public GoldenDoor() {
super();
public GoldenDoor(Location location) {
super(location);
}

public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Location;

public class GrayDoor extends Door {

public GrayDoor(Location location) {
super(location);
}

public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) {
PEGame game = GameManager.getGame();
boolean isOpened = isOpened();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package net.tiagofar78.prisonescape.items;

import net.tiagofar78.prisonescape.game.PEGame;
import net.tiagofar78.prisonescape.managers.GameManager;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerInteractEvent;

import java.util.ArrayList;
Expand Down Expand Up @@ -35,8 +37,12 @@ public void use(PlayerInteractEvent e) {
return;
}

PEGame game = GameManager.getGame();
Location blockLoc = getPlacedBlockLocation(block.getLocation(), e.getBlockFace());
GameManager.getGame().placeBomb(blockLoc);
game.placeBomb(blockLoc);

Player player = e.getPlayer();
game.getPEPlayer(player.getName()).removeItem(player.getInventory().getHeldItemSlot());
}

private Location getPlacedBlockLocation(Location blockLocation, BlockFace face) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public boolean isIllegal() {

@Override
public Material getMaterial() {
return Material.TORCH;
return Material.BLAZE_ROD;
}

@Override
Expand Down

0 comments on commit 4976d27

Please sign in to comment.