Skip to content

Commit

Permalink
feat: port 0.2.31 and 0.2.32 changes and fixes
Browse files Browse the repository at this point in the history
5fc4ffb - fix: fix wrong timezone configuration when connecting to database by making it configurable
8477933 - feat: go to snapshot, BedWarsGameEnabledEvent, BedWarsGameDisabledEvent
  • Loading branch information
Misat11 committed Jan 13, 2024
1 parent a5d6125 commit 7a6abd5
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2023 ScreamingSandals
*
* This file is part of Screaming BedWars.
*
* Screaming BedWars is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Screaming BedWars is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
*/

package org.screamingsandals.bedwars.api.events;

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.BedwarsAPI;
import org.screamingsandals.bedwars.api.game.Game;

import java.util.function.Consumer;

@ApiStatus.NonExtendable
public interface GameDisabledEvent {
Game getGame();

static void handle(Object plugin, Consumer<GameDisabledEvent> consumer) {
BedwarsAPI.getInstance().getEventUtils().handle(plugin, GameDisabledEvent.class, consumer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2023 ScreamingSandals
*
* This file is part of Screaming BedWars.
*
* Screaming BedWars is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Screaming BedWars is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
*/

package org.screamingsandals.bedwars.api.events;

import org.jetbrains.annotations.ApiStatus;
import org.screamingsandals.bedwars.api.BedwarsAPI;
import org.screamingsandals.bedwars.api.game.Game;

import java.util.function.Consumer;

@ApiStatus.NonExtendable
public interface GameEnabledEvent {
Game getGame();

static void handle(Object plugin, Consumer<GameEnabledEvent> consumer) {
BedwarsAPI.getInstance().getEventUtils().handle(plugin, GameEnabledEvent.class, consumer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ public void load() {
.key("password").defValue("secret")
.key("table-prefix").defValue("bw_")
.key("useSSL").defValue(false)
.key("add-timezone-to-connection-string").defValue(true)
.key("timezone-id").defValue(TimeZone.getDefault().getID())
.back()
.section("bossbar")
.key("use-xp-bar").defValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class DatabaseManager {
private int port;
private String user;
private boolean useSSL;
private boolean addTimezone;
private String timezoneID;

public static DatabaseManager getInstance() {
return ServiceManager.get(DatabaseManager.class);
Expand All @@ -58,12 +60,14 @@ public void onEnable() {
this.database = mainConfig.node("database", "db").getString();
this.tablePrefix = mainConfig.node("database", "table-prefix").getString();
this.useSSL = mainConfig.node("database", "useSSL").getBoolean();
this.addTimezone = mainConfig.node("database", "add-timezone-to-connection-string").getBoolean();
this.timezoneID = mainConfig.node("database", "timezone-id").getString();
}

public void initialize() {
var config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database
+ "?autoReconnect=true&serverTimezone=" + TimeZone.getDefault().getID() + "&useSSL=" + useSSL);
+ "?autoReconnect=true" + (addTimezone && timezoneID != null ? "&serverTimezone=" + timezoneID : "") + "&useSSL=" + useSSL);
config.setUsername(this.user);
config.setPassword(this.password);
config.addDataSourceProperty("cachePrepStmts", "true");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 ScreamingSandals
*
* This file is part of Screaming BedWars.
*
* Screaming BedWars is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Screaming BedWars is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
*/

package org.screamingsandals.bedwars.events;

import lombok.Data;
import org.screamingsandals.bedwars.api.events.GameDisabledEvent;
import org.screamingsandals.bedwars.game.GameImpl;
import org.screamingsandals.lib.event.Event;

@Data
public class GameDisabledEventImpl implements GameDisabledEvent, Event {
private final GameImpl game;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2023 ScreamingSandals
*
* This file is part of Screaming BedWars.
*
* Screaming BedWars is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Screaming BedWars is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Screaming BedWars. If not, see <https://www.gnu.org/licenses/>.
*/

package org.screamingsandals.bedwars.events;

import lombok.Data;
import org.screamingsandals.bedwars.api.events.GameEnabledEvent;
import org.screamingsandals.bedwars.game.GameImpl;
import org.screamingsandals.lib.event.Event;

@Data
public class GameEnabledEventImpl implements GameEnabledEvent, Event {
private final GameImpl game;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ public void start() {
statusbar = new BossBarImpl();
}
preparing = false;
EventManager.fire(new GameEnabledEventImpl(this));
}
}

Expand All @@ -1303,6 +1304,7 @@ public void stop() {
} else {
afterRebuild = GameStatus.DISABLED;
}
EventManager.fire(new GameDisabledEventImpl(this));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class EventUtilsImpl implements EventUtils {
Map.entry(ApplyPropertyToDisplayedItemEvent.class, ApplyPropertyToDisplayedItemEventImpl.class),
Map.entry(ApplyPropertyToItemEvent.class, ApplyPropertyToItemEventImpl.class),
Map.entry(GameChangedStatusEvent.class, GameChangedStatusEventImpl.class),
Map.entry(GameDisabledEvent.class, GameDisabledEventImpl.class),
Map.entry(GameEnabledEvent.class, GameEnabledEventImpl.class),
Map.entry(GameEndEvent.class, GameEndEventImpl.class),
Map.entry(GameEndingEvent.class, GameEndingEventImpl.class),
Map.entry(GameStartedEvent.class, GameStartedEventImpl.class),
Expand Down

0 comments on commit 7a6abd5

Please sign in to comment.