Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PrinzPizza42 committed Jan 6, 2025
1 parent 73ad6b1 commit 4a881b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/j/deathMinigames/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public HashMap<String, String> getDatabaseConfig() {
return databaseConnectionInfo;
}

public void setServerName(String serverName) {
public synchronized void setServerName(String serverName) {
if(!Main.getPlugin().getConfig().contains("Tablist.ServerName")) {
Main.getPlugin().getConfig().set("Tablist.ServerName", serverName);
Main.getPlugin().saveConfig();
Expand All @@ -345,7 +345,7 @@ public String getServerName() {
}
}

public void setHostetBy(String serverName) {
public synchronized void setHostetBy(String serverName) {
if(!Main.getPlugin().getConfig().contains("Tablist.HostetBy") || !Main.getPlugin().getConfig().getString("Tablist.HostetBy").equals(serverName)) {
Main.getPlugin().getConfig().set("Tablist.HostetBy", serverName);
Main.getPlugin().saveConfig();
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/de/j/deathMinigames/settings/AnvilUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
Expand All @@ -17,10 +18,12 @@
import java.util.concurrent.ThreadLocalRandom;

public class AnvilUI implements InventoryHolder {
private final Location loc = new Location(Bukkit.getWorld("world"), ThreadLocalRandom.current().nextInt(0, 1000), ThreadLocalRandom.current().nextInt(0, 1000), ThreadLocalRandom.current().nextInt(0, 1000));
private Location loc = null;
private final ItemStack firstSlot = new ItemStack(Material.RED_CONCRETE);

public AnvilUI(MainMenu.AnvilUIs title) {
if(title == null) return;
createUniqueLocation();
ItemMeta paperMeta = firstSlot.getItemMeta();
switch (title) {
case SET_HOST_NAME:
Expand All @@ -31,8 +34,11 @@ public AnvilUI(MainMenu.AnvilUIs title) {
if(Config.getInstance().getServerName() != null) paperMeta.displayName(Component.text(Config.getInstance().getServerName()));
else paperMeta.displayName(Component.text("kein Name gesetzt / no name set"));
break;
default:
case DEFAULT:
paperMeta.displayName(Component.text(""));
break;
default:
throw new IllegalArgumentException("Unexpected AnvilUI title: " + title);
}
firstSlot.setItemMeta(paperMeta);
}
Expand All @@ -48,6 +54,19 @@ public void showInventory(Player playerToShowTheInvTo) {
return null;
}

/**
* Random location used as a unique identifier for the anvil UI.
* This prevents conflicts between multiple anvil UIs.
*/
private void createUniqueLocation() {
World world = Bukkit.getWorld("world");
if(world == null) throw new IllegalStateException("world `world´ could not be found");
loc = new Location(world,
ThreadLocalRandom.current().nextInt(0, 1000),
ThreadLocalRandom.current().nextInt(0, 1000),
ThreadLocalRandom.current().nextInt(0, 1000));
}

public boolean compareLocIDTo(Location loc) {
return loc.getBlockX() == this.loc.getBlockX() && loc.getBlockZ() == this.loc.getBlockZ();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/j/deathMinigames/settings/MainMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum InventoryMenus {
public enum AnvilUIs {
SET_SERVER_NAME,
SET_HOST_NAME,
DEFAULT // usage when the input slot item should have no name
}

public MainMenu() {
Expand Down

0 comments on commit 4a881b9

Please sign in to comment.