Skip to content

Commit

Permalink
Salvar file async e removido verificação de chave física
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock committed Apr 6, 2024
1 parent fc86d9f commit e1fec89
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
1 change: 1 addition & 0 deletions paper/run/config/paper-global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ unsupported-settings:
allow-headless-pistons: false
allow-permanent-block-break-exploits: false
allow-piston-duplication: false
allow-tripwire-disarming-exploits: false
allow-unsafe-end-portal-teleportation: false
compression-format: ZLIB
perform-username-validation: true
Expand Down
2 changes: 1 addition & 1 deletion paper/run/server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Minecraft server properties
#Fri Mar 08 12:37:41 GMT-03:00 2024
#Sat Apr 06 16:10:24 GMT-03:00 2024
enable-jmx-monitoring=false
rcon.port=25575
level-seed=
Expand Down
24 changes: 13 additions & 11 deletions paper/src/main/java/com/badbones69/crazycrates/api/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -23,12 +23,12 @@ public class FileManager {
@NotNull
private final CrazyCrates plugin = CrazyCrates.get();

private final Map<Files, File> files = new HashMap<>();
private final Map<Files, File> files = new ConcurrentHashMap<>();
private final List<String> homeFolders = new ArrayList<>();
private final List<CustomFile> customFiles = new ArrayList<>();
private final Map<String, String> jarHomeFolders = new HashMap<>();
private final Map<String, String> autoGenerateFiles = new HashMap<>();
private final Map<Files, FileConfiguration> configurations = new HashMap<>();
private final Map<String, String> jarHomeFolders = new ConcurrentHashMap<>();
private final Map<String, String> autoGenerateFiles = new ConcurrentHashMap<>();
private final Map<Files, FileConfiguration> configurations = new ConcurrentHashMap<>();
private final Logger logger = this.plugin.getLogger();
private final boolean isLogging = this.plugin.isLogging();

Expand Down Expand Up @@ -343,7 +343,7 @@ public void reloadAllFiles() {
* @return A list of crate names.
*/
public List<String> getAllCratesNames() {
List<String> files = new ArrayList<>();
List<String> fileList = new ArrayList<>();

File crateDirectory = new File(this.plugin.getDataFolder(), "/crates");

Expand All @@ -361,7 +361,7 @@ public List<String> getAllCratesNames() {
for (String name : folder) {
if (!name.endsWith(".yml")) continue;

files.add(name.replaceAll(".yml", ""));
fileList.add(name.replaceAll(".yml", ""));
}
}
}
Expand All @@ -371,11 +371,11 @@ public List<String> getAllCratesNames() {
for (String name : file) {
if (!name.endsWith(".yml")) continue;

files.add(name.replaceAll(".yml", ""));
fileList.add(name.replaceAll(".yml", ""));
}
}

return Collections.unmodifiableList(files);
return Collections.unmodifiableList(fileList);
}

/**
Expand Down Expand Up @@ -473,14 +473,16 @@ public FileConfiguration getFile() {
* Saves the file from the loaded state to the file system.
*/
public void saveFile() {
this.fileManager.saveFile(this);
Bukkit.getAsyncScheduler().runNow(this.plugin, task -> this.fileManager.saveFile(this));
}

/**
* Overrides the loaded state file and loads the file systems file.
*/
public void reloadFile() {
if (getFileName().endsWith(".yml")) this.fileManager.reloadFile(this);
if (getFileName().endsWith(".yml")) {
this.fileManager.reloadFile(this);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public void onCrateOpen(PlayerInteractEvent e) {
Player player = e.getPlayer();

if (e.getHand() == EquipmentSlot.OFF_HAND) {
if (this.plugin.getCrateManager().isKey(player.getInventory().getItemInOffHand())) {
e.setCancelled(true);
player.updateInventory();
}
// if (this.plugin.getCrateManager().isKey(player.getInventory().getItemInOffHand())) {
// e.setCancelled(true);
// player.updateInventory();
// }

return;
}
Expand Down Expand Up @@ -94,15 +94,17 @@ public void onCrateOpen(PlayerInteractEvent e) {
}
} else if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
// Checks if the item in their hand is a key and if so it stops them from right-clicking with it.
ItemStack key = player.getInventory().getItemInMainHand();
boolean keyInHand = this.crateManager.isKey(key);

if (!keyInHand) keyInHand = this.crateManager.isKey(player.getEquipment().getItemInOffHand());

if (keyInHand) {
e.setCancelled(true);
player.updateInventory();
}
// ItemStack key = player.getInventory().getItemInMainHand();
// boolean keyInHand = this.crateManager.isKey(key);
//
// if (!keyInHand) {
// keyInHand = this.crateManager.isKey(player.getEquipment().getItemInOffHand());
// }
//
// if (keyInHand) {
// e.setCancelled(true);
// player.updateInventory();
// }

//Checks to see if the clicked block is a physical crate.
CrateLocation crateLocation = null;
Expand Down Expand Up @@ -134,7 +136,7 @@ public void onCrateOpen(PlayerInteractEvent e) {

if (!event.isCancelled()) {
boolean hasKey = false;
boolean isPhysical = false;
// boolean isPhysical = false;
boolean useQuickCrateAgain = false;
String keyName = crate.getKeyName();

Expand All @@ -152,13 +154,15 @@ public void onCrateOpen(PlayerInteractEvent e) {
return;
}

if (crate.getCrateType() != CrateType.crate_on_the_go && keyInHand && this.crateManager.isKeyFromCrate(key, crate) && this.config.getProperty(ConfigKeys.physical_accepts_physical_keys)) {
// if (crate.getCrateType() != CrateType.crate_on_the_go && keyInHand && this.crateManager.isKeyFromCrate(key, crate) && this.config.getProperty(ConfigKeys.physical_accepts_physical_keys)) {
// hasKey = true;
// isPhysical = true;
// }

if (this.config.getProperty(ConfigKeys.physical_accepts_virtual_keys) && this.plugin.getCrazyHandler().getUserManager().getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1) {
hasKey = true;
isPhysical = true;
}

if (this.config.getProperty(ConfigKeys.physical_accepts_virtual_keys) && this.plugin.getCrazyHandler().getUserManager().getVirtualKeys(player.getUniqueId(), crate.getName()) >= 1) hasKey = true;

if (hasKey) {
// Checks if the player uses the quick crate again.
if (this.crateManager.isInOpeningList(player) && this.crateManager.getOpeningCrate(player).getCrateType() == CrateType.quick_crate && this.crateManager.isCrateInUse(player) && this.crateManager.getCrateInUseLocation(player).equals(crateLocation.getLocation())) {
Expand Down Expand Up @@ -186,17 +190,21 @@ public void onCrateOpen(PlayerInteractEvent e) {
this.plugin.getCrateManager().endQuickCrate(player, crateLocation.getLocation(), crate, true);
}

KeyType keyType = isPhysical ? KeyType.physical_key : KeyType.virtual_key;
KeyType keyType = KeyType.virtual_key;

// Only cosmic crate type uses this method.
if (crate.getCrateType() == CrateType.cosmic) this.crateManager.addPlayerKeyType(player, keyType);
if (crate.getCrateType() == CrateType.cosmic) {
this.crateManager.addPlayerKeyType(player, keyType);
}

this.crateManager.addPlayerToOpeningList(player, crate);

this.crateManager.openCrate(player, crate, keyType, crateLocation.getLocation(), false,true);
} else {
if (crate.getCrateType() != CrateType.crate_on_the_go) {
if (this.config.getProperty(ConfigKeys.knock_back)) knockBack(player, clickedBlock.getLocation());
if (this.config.getProperty(ConfigKeys.knock_back)) {
knockBack(player, clickedBlock.getLocation());
}

if (this.config.getProperty(ConfigKeys.need_key_sound_toggle)) {
player.playSound(player.getLocation(), Sound.valueOf(this.config.getProperty(ConfigKeys.need_key_sound)), SoundCategory.PLAYERS, 1f, 1f);
Expand Down

0 comments on commit e1fec89

Please sign in to comment.