From 983b1d89c5ac9d8b8bd8a6affe3952acd4154d3a Mon Sep 17 00:00:00 2001 From: Zeanon Date: Wed, 21 Apr 2021 14:22:58 +0200 Subject: [PATCH] . --- .../features/scoreboard/Scoreboard.java | 94 +++++++++++++++++++ .../features/scoreboard/ScoreboardBundle.java | 75 +++++++++++++++ .../scoreboard/ScoreboardManager.java | 31 ++++++ .../implementations/BelownameBoard.java | 39 ++++++++ .../implementations/PlayerlistBoard.java | 39 ++++++++ .../implementations/SidebarBoard.java | 54 +++++++++++ 6 files changed, 332 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/Scoreboard.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardBundle.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardManager.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/BelownameBoard.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/PlayerlistBoard.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/SidebarBoard.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/Scoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/Scoreboard.java new file mode 100644 index 00000000..a4a89df4 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/Scoreboard.java @@ -0,0 +1,94 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard; + +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; + + +public abstract class Scoreboard { + + private final String name; + private String displayName; + private final DisplaySlot displaySlot; + private UpdateMode updateMode; + private long lastChanged; + private long lastSended; + + protected Scoreboard(final String name, final String displayName, final DisplaySlot displaySlot) { + this.name = name; + this.displayName = displayName; + this.displaySlot = displaySlot; + this.updateMode = UpdateMode.INTELLIGENT; + this.lastChanged = System.currentTimeMillis(); + this.lastSended = System.currentTimeMillis(); + } + + protected Scoreboard(final String name, final String displayName, final DisplaySlot displaySlot, final UpdateMode updateMode) { + this.name = name; + this.displayName = displayName; + this.displaySlot = displaySlot; + this.updateMode = updateMode; + this.lastChanged = System.currentTimeMillis(); + this.lastSended = System.currentTimeMillis(); + } + + + public boolean hasChanged() { + return this.lastSended < this.lastChanged; + } + + + public void sendBoard(final Player p) { + if (this.needsSend()) { + this.internalSendBoard(p); + this.lastSended = System.currentTimeMillis(); + } + } + + public void updateLine(final String name, final String displayName) { + this.internalUpdateLine(name, displayName); + this.lastChanged = System.currentTimeMillis(); + } + + + protected abstract void internalUpdateLine(final String name, final String displayName); + + protected abstract void internalSendBoard(final Player p); + + private boolean needsSend() { + switch (this.updateMode) { + case MANUAL: + return false; + case AUTOMATIC: + return true; + case INTELLIGENT: + default: + return this.hasChanged(); + } + } + + public enum UpdateMode { + + AUTOMATIC, + INTELLIGENT, + MANUAL + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardBundle.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardBundle.java new file mode 100644 index 00000000..0c4ba6e9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardBundle.java @@ -0,0 +1,75 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard; + +import de.steamwar.bausystem.features.scoreboard.implementations.BelownameBoard; +import de.steamwar.bausystem.features.scoreboard.implementations.PlayerlistBoard; +import de.steamwar.bausystem.features.scoreboard.implementations.SidebarBoard; +import java.util.ArrayList; +import java.util.List; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; + + +public class ScoreboardBundle { + + private final List scoreboards; + private final Player p; + + public ScoreboardBundle(final Player p) { + this.p = p; + this.scoreboards = new ArrayList<>(); + } + + public void registerBoard(final Scoreboard scoreboard) { + this.scoreboards.add(scoreboard); + } + + public Scoreboard registerNewBoard(final String name, final DisplaySlot displaySlot) { + final Scoreboard scoreboard; + switch (displaySlot) { + case BELOW_NAME: + scoreboard = new BelownameBoard(name); + break; + case PLAYER_LIST: + scoreboard = new PlayerlistBoard(name); + break; + case SIDEBAR: + default: + scoreboard = new SidebarBoard(name); + break; + } + + this.registerBoard(scoreboard); + return scoreboard; + } + + public Scoreboard getBoard(final String name) { + return this.scoreboards.stream().filter(scoreboard -> scoreboard.getName().equals(name)).findFirst().orElse(null); + } + + public Scoreboard getBoard(final String name, final DisplaySlot displaySlot) { + return this.scoreboards.stream().filter(scoreboard -> scoreboard.getName().equals(name)).filter(scoreboard -> scoreboard.getDisplaySlot() == displaySlot).findFirst().orElse(null); + } + + public Scoreboard getOrRegisterBoard(final String name, final DisplaySlot displaySlot) { + return this.scoreboards.stream().filter(scoreboard -> scoreboard.getName().equals(name)).filter(scoreboard -> scoreboard.getDisplaySlot() == displaySlot).findFirst().orElse(this.registerNewBoard(name, displaySlot)); + } +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardManager.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardManager.java new file mode 100644 index 00000000..a80e6c49 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/ScoreboardManager.java @@ -0,0 +1,31 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard; + +import java.util.ArrayList; +import java.util.List; + + +public class ScoreboardManager { + + private final List scoreboardBundles = new ArrayList<>(); + + +} \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/BelownameBoard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/BelownameBoard.java new file mode 100644 index 00000000..63745f2b --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/BelownameBoard.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard.implementations; + +import de.steamwar.bausystem.features.scoreboard.Scoreboard; +import org.bukkit.scoreboard.DisplaySlot; + + +public class BelownameBoard extends Scoreboard { + + public BelownameBoard(String name, String displayName) { + super(name, displayName, DisplaySlot.BELOW_NAME); + } + + public BelownameBoard(String name, String displayName, UpdateMode updateMode) { + super(name, displayName, DisplaySlot.BELOW_NAME, updateMode); + } + + public BelownameBoard(String name) { + super(name, name, DisplaySlot.BELOW_NAME); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/PlayerlistBoard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/PlayerlistBoard.java new file mode 100644 index 00000000..22d6157c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/PlayerlistBoard.java @@ -0,0 +1,39 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard.implementations; + +import de.steamwar.bausystem.features.scoreboard.Scoreboard; +import org.bukkit.scoreboard.DisplaySlot; + + +public class PlayerlistBoard extends Scoreboard { + + public PlayerlistBoard(String name, String displayName) { + super(name, displayName, DisplaySlot.PLAYER_LIST); + } + + public PlayerlistBoard(String name, String displayName, UpdateMode updateMode) { + super(name, displayName, DisplaySlot.BELOW_NAME, updateMode); + } + + public PlayerlistBoard(String name) { + super(name, name, DisplaySlot.PLAYER_LIST); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/SidebarBoard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/SidebarBoard.java new file mode 100644 index 00000000..d0d72c79 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/scoreboard/implementations/SidebarBoard.java @@ -0,0 +1,54 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.scoreboard.implementations; + +import de.steamwar.bausystem.features.scoreboard.Scoreboard; +import java.util.HashMap; +import java.util.Map; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; + + +public class SidebarBoard extends Scoreboard { + + private final Map data = new HashMap<>(); + + public SidebarBoard(String name, String displayName) { + super(name, displayName, DisplaySlot.SIDEBAR); + } + + public SidebarBoard(String name, String displayName, UpdateMode updateMode) { + super(name, displayName, DisplaySlot.BELOW_NAME, updateMode); + } + + public SidebarBoard(String name) { + super(name, name, DisplaySlot.SIDEBAR); + } + + @Override + protected void internalUpdateLine(String name, String displayName) { + this.data.put(name, displayName); + } + + @Override + protected void internalSendBoard(Player p) { + + } +} \ No newline at end of file