Skip to content

Commit

Permalink
Merge pull request #205 from TiagoFar78/shopVariables
Browse files Browse the repository at this point in the history
Shop variables
  • Loading branch information
iquelli authored May 11, 2024
2 parents cb45acf + 9ea545d commit 28b6fb1
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 59 deletions.
12 changes: 12 additions & 0 deletions TestServer/plugins/TF_PrisonEscape/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ SecondsInSolitary: 30
DaysAmount: 4
DayDuration: 120
NightDuration: 60
StartingBalance: 100
TrapLimit: 2
SensorLimit: 2
RadarLimit: -1
EnergyDrinkLimit: -1
CameraLimit: 1
TrapPrice: 10
SensorPrice: 10
RadarPrice: 10
EnergyDrinkPrice: 10
CameraPrice: 10
WaitingPhaseDuration: 300
FullLobbyWaitDuration: 10
FinishedPhaseDuration: 30
Expand Down Expand Up @@ -131,6 +142,7 @@ PoliceSecretPassagesLocation:
X: 3
Y: 100
Z: 8
VaultsDirection: "WEST"
VaultsLocations:
"1":
X: 5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.data.type.Door;
import org.bukkit.block.sign.Side;
import org.bukkit.entity.TNTPrimed;

public class BukkitWorldEditor {
Expand All @@ -21,35 +19,6 @@ public static World getWorld() {
return WORLD;
}

// #########################################
// # Vault #
// #########################################

private static final int SIGN_INDEX = 1;

public static void addSignAboveVault(PrisonEscapeLocation location, String text) {
Location bukkitLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ());
bukkitLocation.getBlock().setType(Material.OAK_WALL_SIGN);
Sign sign = (Sign) bukkitLocation.getBlock().getState();
sign.getSide(Side.FRONT).setLine(SIGN_INDEX, text);
sign.update();
}

public static void addVault(PrisonEscapeLocation location) {
Location bukkitLocation = new Location(WORLD, location.getX(), location.getY(), location.getZ());

Block block = bukkitLocation.getBlock();
block.setType(Material.CHEST);
}

public static void deleteVaultAndRespectiveSign(PrisonEscapeLocation location) {
Location vaultLocation = new Location(WORLD, location.getX(), location.getY(), location.getZ());
Location signLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ());

vaultLocation.getBlock().setType(Material.AIR);
signLocation.getBlock().setType(Material.AIR);
}

// ########################################
// # Time #
// ########################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class PrisonBuilding {

private static final String PRISON_REGION_NAME = "PRISON";

private PrisonEscapeLocation _reference;

private PrisonEscapeLocation _waitingLobbyLocation;
private Region _prison;
private List<Region> _regions;
Expand All @@ -34,7 +36,6 @@ public class PrisonBuilding {
private Hashtable<String, PrisonEscapeLocation> _policeSecretPassageLocations;

private List<Vault> _vaults;
private List<PrisonEscapeLocation> _vaultsLocations;

private Hashtable<String, Chest> _chests;
private Hashtable<String, Door> _doors;
Expand All @@ -53,6 +54,8 @@ public class PrisonBuilding {
public PrisonBuilding(PrisonEscapeLocation reference) {
ConfigManager config = ConfigManager.getInstance();

_reference = reference;

PrisonEscapeLocation prisonUpperCorner = config.getPrisonUpperCornerLocation().add(reference);
PrisonEscapeLocation prisonLowerCorner = config.getPrisonLowerCornerLocation().add(reference);
_prison = new SquaredRegion(PRISON_REGION_NAME, false, true, prisonUpperCorner, prisonLowerCorner);
Expand All @@ -74,7 +77,6 @@ public PrisonBuilding(PrisonEscapeLocation reference) {
_policeSecretPassageLocations = createLocationsMap(reference, config.getPoliceSecretPassageLocations());

_vaults = new ArrayList<>();
_vaultsLocations = createLocationsList(reference, config.getVaultsLocations());

_chests = new Hashtable<>();
for (PrisonEscapeLocation loc : config.getChestsLocations()) {
Expand Down Expand Up @@ -232,13 +234,11 @@ public boolean checkIfMetalDetectorTriggered(PrisonEscapeLocation location, Pris
// #########################################

public void addVaults(List<PrisonEscapePlayer> prisioners) {
for (int i = 0; i < prisioners.size(); i++) {
_vaults.add(new Vault(prisioners.get(i)));
ConfigManager config = ConfigManager.getInstance();
List<PrisonEscapeLocation> vaultsLocations = createLocationsList(_reference, config.getVaultsLocations());

String signText = prisioners.get(i).getName();
PrisonEscapeLocation vaultLocation = _vaultsLocations.get(i);
BukkitWorldEditor.addSignAboveVault(vaultLocation, signText);
BukkitWorldEditor.addVault(vaultLocation);
for (int i = 0; i < prisioners.size(); i++) {
_vaults.add(new Vault(prisioners.get(i), vaultsLocations.get(i)));
}
}

Expand All @@ -247,8 +247,8 @@ public Vault getVault(int index) {
}

public int getVaultIndex(PrisonEscapeLocation location) {
for (int i = 0; i < _vaultsLocations.size(); i++) {
if (_vaultsLocations.get(i).equals(location)) {
for (int i = 0; i < _vaults.size(); i++) {
if (_vaults.get(i).isIn(location)) {
return i;
}
}
Expand All @@ -257,8 +257,8 @@ public int getVaultIndex(PrisonEscapeLocation location) {
}

public void deleteVaults() {
for (PrisonEscapeLocation location : _vaultsLocations) {
BukkitWorldEditor.deleteVaultAndRespectiveSign(location);
for (Vault vault : _vaults) {
vault.deleteVaultAndRespectiveSignFromWorld();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
package net.tiagofar78.prisonescape.game.prisonbuilding;

import net.tiagofar78.prisonescape.bukkit.BukkitMenu;
import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor;
import net.tiagofar78.prisonescape.game.PrisonEscapePlayer;
import net.tiagofar78.prisonescape.items.Item;
import net.tiagofar78.prisonescape.items.NullItem;
import net.tiagofar78.prisonescape.managers.ConfigManager;
import net.tiagofar78.prisonescape.menus.ClickReturnAction;
import net.tiagofar78.prisonescape.menus.Clickable;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Sign;
import org.bukkit.block.data.Directional;
import org.bukkit.block.sign.Side;

import java.util.ArrayList;
import java.util.List;

public class Vault implements Clickable {

private static final int NON_HIDDEN_SIZE = 4;
private static final int HIDDEN_SIZE = 1;
private static final int SIGN_OWNER_NAME_LINE__INDEX = 1;

private List<Item> _nonHiddenContents;
private List<Item> _hiddenContents;
private boolean _isOpen;

private PrisonEscapePlayer _owner;

public Vault(PrisonEscapePlayer owner) {
private PrisonEscapeLocation _location;

public Vault(PrisonEscapePlayer owner, PrisonEscapeLocation location) {
_nonHiddenContents = createContentsList(NON_HIDDEN_SIZE);
_hiddenContents = createContentsList(HIDDEN_SIZE);
_isOpen = false;

this._owner = owner;
_owner = owner;

_location = location;
createWorldVault(location);
createWorldSignAboveVault(location, _owner.getName());
}

public boolean isIn(PrisonEscapeLocation location) {
return _location.equals(location);
}

private List<Item> createContentsList(int size) {
Expand Down Expand Up @@ -116,4 +138,48 @@ public ClickReturnAction click(PrisonEscapePlayer player, int slot, Item itemHel
return ClickReturnAction.CHANGE_HOLD_AND_SELECTED;
}

// #########################################
// # World #
// #########################################

private void createWorldVault(PrisonEscapeLocation location) {
World world = BukkitWorldEditor.getWorld();
Location bukkitLocation = new Location(world, location.getX(), location.getY(), location.getZ());

Block block = bukkitLocation.getBlock();
block.setType(Material.CHEST);

rotate(block);
}

private void createWorldSignAboveVault(PrisonEscapeLocation location, String text) {
World world = BukkitWorldEditor.getWorld();
Location bukkitLocation = new Location(world, location.getX(), location.getY() + 1, location.getZ());
Block block = bukkitLocation.getBlock();
block.setType(Material.OAK_WALL_SIGN);

rotate(block);

Sign sign = (Sign) block.getState();
sign.getSide(Side.FRONT).setLine(SIGN_OWNER_NAME_LINE__INDEX, text);
sign.update();
}

private void rotate(Block block) {
ConfigManager config = ConfigManager.getInstance();

Directional rotatable = (Directional) block.getBlockData();
rotatable.setFacing(BlockFace.valueOf(config.getVaultsDirection()));
block.setBlockData(rotatable);
}

public void deleteVaultAndRespectiveSignFromWorld() {
World world = BukkitWorldEditor.getWorld();
Location vaultLocation = new Location(world, _location.getX(), _location.getY(), _location.getZ());
Location signLocation = new Location(world, _location.getX(), _location.getY() + 1, _location.getZ());

vaultLocation.getBlock().setType(Material.AIR);
signLocation.getBlock().setType(Material.AIR);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static ConfigManager getInstance() {
private Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> _prisionersSecretPassageLocations;
private Hashtable<PrisonEscapeLocation, PrisonEscapeLocation> _policeSecretPassageLocations;
private List<PrisonEscapeLocation> _vaultsLocations;
private String _vaultsDirection;
private List<PrisonEscapeLocation> _chestsLocations;
private List<PrisonEscapeLocation> _goldenDoorsLocations;
private List<PrisonEscapeLocation> _grayDoorsLocations;
Expand Down Expand Up @@ -143,6 +144,7 @@ public ConfigManager() {
_prisionersSecretPassageLocations = createLocationsMap(config, "PrisionersSecretPassagesLocation");
_policeSecretPassageLocations = createLocationsMap(config, "PoliceSecretPassagesLocation");
_vaultsLocations = createLocationList(config, "VaultsLocations");
_vaultsDirection = config.getString("VaultsDirection");
_chestsLocations = createLocationList(config, "ChestsLocations");
_goldenDoorsLocations = createLocationList(config, "GoldenDoorsLocations");
_grayDoorsLocations = createLocationList(config, "GrayDoorsLocations");
Expand Down Expand Up @@ -489,6 +491,10 @@ public List<PrisonEscapeLocation> getVaultsLocations() {
return createLocationsListCopy(_vaultsLocations);
}

public String getVaultsDirection() {
return _vaultsDirection;
}

public List<PrisonEscapeLocation> getChestsLocations() {
return createLocationsListCopy(_chestsLocations);
}
Expand Down
29 changes: 15 additions & 14 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,24 @@ SecondsInSolitary: 30
DaysAmount: 4
DayDuration: 120
NightDuration: 60
StartingBalance: 100
TrapLimit: 2
SensorLimit: 2
RadarLimit: -1
EnergyDrinkLimit: -1
CameraLimit: 1
TrapPrice: 10
SensorPrice: 10
RadarPrice: 10
EnergyDrinkPrice: 10
CameraPrice: 10
WaitingPhaseDuration: 300
FullLobbyWaitDuration: 10
FinishedPhaseDuration: 30
DelayBetweenAnnouncements: 30
CommonItemsProbability: 0.8
RareItemsProbability: 0.25
ChestSize: 5
SpeedDuration: 15
SpeedLevel: 2
HelicopterSpawnDelay: 10
Expand Down Expand Up @@ -94,6 +108,7 @@ PoliceSecretPassagesLocation:
X: 0
Y: 0
Z: 0
VaultsDirection: "NORTH"
VaultsLocations:
"1":
X: 0
Expand Down Expand Up @@ -177,17 +192,3 @@ Vents:
X: 0
Y: 0
Z: 0
CommonItemsProbability: 0.8
RareItemsProbability: 0.25
ChestSize: 5
StartingBalance: 100
TrapLimit: 2
SensorLimit: 2
RadarLimit: -1
EnergyDrinkLimit: -1
CameraLimit: 1
TrapPrice: 10
SensorPrice: 10
RadarPrice: 10
EnergyDrinkPrice: 10
CameraPrice: 10

0 comments on commit 28b6fb1

Please sign in to comment.