SteamWar/BauSystem2.0
Archiviert
12
0
Dieser Commit ist enthalten in:
Zeanon 2021-04-21 14:22:58 +02:00
Ursprung f0fa92f5ca
Commit 983b1d89c5
6 geänderte Dateien mit 332 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<Scoreboard> 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));
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem.features.scoreboard;
import java.util.ArrayList;
import java.util.List;
public class ScoreboardManager {
private final List<ScoreboardBundle> scoreboardBundles = new ArrayList<>();
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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<String, String> 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) {
}
}