Remove announcers
This commit is contained in:
parent
51eaf2a0b3
commit
16f138aadd
|
@ -21,8 +21,6 @@ import de.erethon.caliburn.mob.ExMob;
|
|||
import de.erethon.dungeonsxl.adapter.block.BlockAdapter;
|
||||
import de.erethon.dungeonsxl.adapter.block.BlockAdapterBlockData;
|
||||
import de.erethon.dungeonsxl.adapter.block.BlockAdapterMagicValues;
|
||||
import de.erethon.dungeonsxl.announcer.AnnouncerCache;
|
||||
import de.erethon.dungeonsxl.announcer.AnnouncerListener;
|
||||
import de.erethon.dungeonsxl.api.DungeonModule;
|
||||
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
||||
import de.erethon.dungeonsxl.api.Requirement;
|
||||
|
@ -126,7 +124,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
|||
public static final String[] EXCLUDED_FILES = {"config.yml", "uid.dat", "DXLData.data", "data"};
|
||||
|
||||
/* Folders of internal features */
|
||||
public static final File ANNOUNCERS = new File(SCRIPTS, "announcers");
|
||||
public static final File SIGNS = new File(SCRIPTS, "signs");
|
||||
public static final File COMMANDS = new File(SCRIPTS, "commands");
|
||||
|
||||
|
@ -220,7 +217,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
|||
private DCommandCache dCommands;
|
||||
private TriggerTypeCache triggers;
|
||||
private GlobalProtectionCache protections;
|
||||
private AnnouncerCache announcers;
|
||||
private Registry<String, SignScript> signScriptRegistry;
|
||||
private Registry<String, CommandScript> commandScriptRegistry;
|
||||
|
||||
|
@ -287,7 +283,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
|||
MAPS.mkdir();
|
||||
PLAYERS.mkdir();
|
||||
SCRIPTS.mkdir();
|
||||
ANNOUNCERS.mkdir();
|
||||
CLASSES.mkdir();
|
||||
DUNGEONS.mkdir();
|
||||
SIGNS.mkdir();
|
||||
|
@ -353,10 +348,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
|||
}
|
||||
|
||||
/* Scripts & global data */
|
||||
announcers = new AnnouncerCache(this);
|
||||
manager.registerEvents(new AnnouncerListener(this), this);
|
||||
announcers.init(ANNOUNCERS);
|
||||
|
||||
classRegistry = new Registry<>();
|
||||
for (File script : FileUtil.getFilesForFolder(CLASSES)) {
|
||||
PlayerClass clss = new PlayerClass(caliburn, script);
|
||||
|
@ -627,13 +618,6 @@ public class DungeonsXL extends DREPlugin implements DungeonsAPI {
|
|||
return protections;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the loaded instance of AnnouncerCache
|
||||
*/
|
||||
public AnnouncerCache getAnnouncerCache() {
|
||||
return announcers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a registry of the loaded sign scripts.
|
||||
*
|
||||
|
|
|
@ -1,453 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Dungeon;
|
||||
import de.erethon.dungeonsxl.api.event.group.GroupCreateEvent.Cause;
|
||||
import de.erethon.dungeonsxl.api.player.PlayerGroup.Color;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.util.GUIUtil;
|
||||
import de.erethon.dungeonsxl.util.commons.chat.DefaultFontInfo;
|
||||
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
/**
|
||||
* Represents a game announcement.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class Announcer {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> description;
|
||||
private List<String> worlds;
|
||||
|
||||
private String dungeonName;
|
||||
private String mapName;
|
||||
|
||||
private int minGroupsPerGame;
|
||||
private int minPlayersPerGroup;
|
||||
|
||||
private short maxGroupsPerGame;
|
||||
private int maxPlayersPerGroup;
|
||||
|
||||
private List<DGroup> dGroups;
|
||||
private List<ItemStack> buttons;
|
||||
|
||||
private AnnouncerStartGameTask startTask;
|
||||
|
||||
/**
|
||||
* @param plugin the plugin instance
|
||||
* @param file the script file
|
||||
*/
|
||||
public Announcer(DungeonsXL plugin, File file) {
|
||||
this(plugin, file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin the plugin instance
|
||||
* @param name the name of the Announcer
|
||||
* @param config the config that stores the information
|
||||
*/
|
||||
public Announcer(DungeonsXL plugin, String name, FileConfiguration config) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.name = name;
|
||||
|
||||
description = config.getStringList("description");
|
||||
worlds = config.getStringList("worlds");
|
||||
|
||||
String identifier = config.getString("identifier");
|
||||
boolean multiFloor = config.getBoolean("multiFloor");
|
||||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getStartFloor().getName();
|
||||
}
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
|
||||
minGroupsPerGame = config.getInt("minGroupsPerGame");
|
||||
minPlayersPerGroup = config.getInt("minPlayersPerGroup");
|
||||
|
||||
maxGroupsPerGame = (short) config.getInt("maxGroupsPerGame");
|
||||
dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
|
||||
maxPlayersPerGroup = config.getInt("maxPlayersPerGroup");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the Announcer
|
||||
* @param description the description messages
|
||||
* @param worlds the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
|
||||
* @param identifier the dungeon identifier
|
||||
* @param multiFloor if the identifier refers to an MFD (true) or an SFD (false)
|
||||
* @param maxGroupsPerGame the amount of groups in one game
|
||||
* @param maxPlayersPerGroup the amount of players in one group
|
||||
*/
|
||||
public Announcer(String name, List<String> description, List<String> worlds, String identifier, boolean multiFloor, short maxGroupsPerGame, int maxPlayersPerGroup) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.worlds = worlds;
|
||||
|
||||
if (multiFloor) {
|
||||
dungeonName = identifier;
|
||||
|
||||
Dungeon dungeon = plugin.getDungeonRegistry().get(identifier);
|
||||
if (dungeon != null) {
|
||||
mapName = dungeon.getStartFloor().getName();
|
||||
}
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
|
||||
this.maxGroupsPerGame = maxGroupsPerGame;
|
||||
this.dGroups = new ArrayList<>(Collections.nCopies(maxGroupsPerGame + 1, (DGroup) null));
|
||||
this.maxPlayersPerGroup = maxPlayersPerGroup;
|
||||
}
|
||||
|
||||
/* Getters and setters */
|
||||
/**
|
||||
* @return the name of the announcer
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description messages
|
||||
*/
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(List<String> description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the names of the worlds where the announcement will be seen or null to broadcast it to all worlds
|
||||
*/
|
||||
public List<String> getWorlds() {
|
||||
return worlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worlds the worlds to set
|
||||
*/
|
||||
public void setWorlds(List<String> worlds) {
|
||||
this.worlds = worlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the dungeon
|
||||
*/
|
||||
public String getDungeonName() {
|
||||
return dungeonName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dungeonName the name of the dungeon to set
|
||||
*/
|
||||
public void setDungeonName(String dungeonName) {
|
||||
this.dungeonName = dungeonName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the first or only floor
|
||||
*/
|
||||
public String getMapName() {
|
||||
return mapName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mapName the name of the map to set
|
||||
*/
|
||||
public void setMapName(String mapName) {
|
||||
this.mapName = mapName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum amount of filled groups per game
|
||||
*/
|
||||
public int getMinGroupsPerGame() {
|
||||
return minGroupsPerGame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setMinGroupsPerGame(int amount) {
|
||||
minGroupsPerGame = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the minimum amount of filled groups per game
|
||||
*/
|
||||
public int getMinPlayersPerGroup() {
|
||||
return minPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setMinPlayersPerGroup(int amount) {
|
||||
minPlayersPerGroup = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum amount of groups per game
|
||||
*/
|
||||
public short getMaxGroupsPerGame() {
|
||||
return maxGroupsPerGame;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setMaxGroupsPerGame(short amount) {
|
||||
maxGroupsPerGame = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maximum amount of players per group
|
||||
*/
|
||||
public int getMaxPlayersPerGroup() {
|
||||
return maxPlayersPerGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the DGroups
|
||||
*/
|
||||
public List<DGroup> getDGroups() {
|
||||
return dGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the buttons that represent the DGroups
|
||||
*/
|
||||
public List<ItemStack> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setMaxPlayersPerGroup(int amount) {
|
||||
maxPlayersPerGroup = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start task
|
||||
*/
|
||||
public AnnouncerStartGameTask getStartTask() {
|
||||
return startTask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether enough players and groups joined the announced game to start
|
||||
*/
|
||||
public boolean areRequirementsFulfilled() {
|
||||
int i = 0;
|
||||
for (DGroup group : dGroups) {
|
||||
if (group != null && group.getMembers().size() >= minPlayersPerGroup) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return i >= minGroupsPerGame;
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
/**
|
||||
* Cancels the start task and sets it to null.
|
||||
*/
|
||||
public void endStartTask() {
|
||||
startTask.cancel();
|
||||
startTask = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the announcement
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
public void send(Player player) {
|
||||
for (String message : description) {
|
||||
MessageUtil.sendCenteredMessage(player, message);
|
||||
}
|
||||
|
||||
ClickEvent onClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/dungeonsxl join " + name);
|
||||
|
||||
BaseComponent[] message = TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', DMessage.ANNOUNCER_CLICK.getMessage()));
|
||||
for (BaseComponent slice : message) {
|
||||
slice.setClickEvent(onClick);
|
||||
}
|
||||
|
||||
TextComponent center = new TextComponent(DefaultFontInfo.center(BaseComponent.toPlainText(message)).replaceAll(BaseComponent.toPlainText(message), ""));
|
||||
|
||||
ArrayList<BaseComponent> toSend = new ArrayList<>(Arrays.asList(message));
|
||||
toSend.add(0, center);
|
||||
MessageUtil.sendMessage(player, toSend.toArray(new BaseComponent[]{}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the group selection GUI
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
public void showGUI(Player player) {
|
||||
updateButtons();
|
||||
Inventory gui = GUIUtil.createGUI(plugin, ChatColor.DARK_RED + name, buttons);
|
||||
plugin.getGUIs().add(gui);
|
||||
player.openInventory(gui);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player
|
||||
* @param button the clicked button
|
||||
*/
|
||||
public void clickGroupButton(Player player, ItemStack button) {
|
||||
DGroup dGroup = getDGroupByButton(button);
|
||||
DGroup pGroup = (DGroup) plugin.getPlayerGroup(player);
|
||||
Color color = Color.getByWoolType(plugin.getCaliburn().getExItem(button));
|
||||
|
||||
for (DGroup group : dGroups) {
|
||||
if (dGroups.contains(pGroup) && pGroup != null && pGroup.isCustom() && pGroup.getLeader() == player) {
|
||||
dGroups.set(dGroups.indexOf(pGroup), null);
|
||||
}
|
||||
|
||||
if (group != null && group.getMembers().contains(player)) {
|
||||
group.removeMember(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (dGroup != null && pGroup == null) {
|
||||
if (dGroup.getMembers().size() < maxPlayersPerGroup) {
|
||||
dGroup.addMember(player);
|
||||
}
|
||||
|
||||
} else if (dGroup == null && pGroup == null) {
|
||||
DGroup group = DGroup.create(plugin, Cause.ANNOUNCER, player, null, color, null);
|
||||
if (group != null) {
|
||||
dGroups.set(buttons.indexOf(button), group);
|
||||
}
|
||||
|
||||
} else if (dGroup == null && pGroup != null) {
|
||||
pGroup.setName(color);
|
||||
dGroups.set(buttons.indexOf(button), pGroup);
|
||||
|
||||
} else if (pGroup != null && dGroups.contains(pGroup) && pGroup != dGroup) {
|
||||
dGroups.set(dGroups.indexOf(pGroup), null);
|
||||
pGroup.setName(color);
|
||||
dGroups.set(buttons.indexOf(button), pGroup);
|
||||
}
|
||||
|
||||
showGUI(player);
|
||||
|
||||
if (areRequirementsFulfilled()) {
|
||||
if (startTask == null) {
|
||||
startTask = new AnnouncerStartGameTask(plugin, this);
|
||||
startTask.runTaskLater(plugin, 20 * 30L);
|
||||
} else {
|
||||
startTask.getProgressBar().addPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the buttons to group changes.
|
||||
*/
|
||||
public void updateButtons() {
|
||||
int groupCount = 0;
|
||||
|
||||
buttons = new ArrayList<>(dGroups.size());
|
||||
do {
|
||||
String name = ChatColor.DARK_GRAY + "EMPTY GROUP";
|
||||
int playerCount = 0;
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
DGroup dGroup = dGroups.get(groupCount);
|
||||
if (!plugin.getGroupCache().contains(dGroup)) {
|
||||
dGroups.set(groupCount, null);
|
||||
|
||||
} else if (dGroup != null) {
|
||||
name = ChatColor.AQUA + dGroup.getName();
|
||||
playerCount = dGroup.getMembers().size();
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
lore.add((dGroup.getLeader().equals(player) ? ChatColor.GOLD : ChatColor.GRAY) + player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
boolean full = playerCount >= maxPlayersPerGroup;
|
||||
|
||||
Color color = plugin.getMainConfig().getGroupColorPriority(groupCount);
|
||||
ItemStack button = color.getWoolMaterial().toItemStack();
|
||||
ItemMeta meta = button.getItemMeta();
|
||||
meta.setDisplayName(name + (full ? ChatColor.DARK_RED : ChatColor.GREEN) + " [" + playerCount + "/" + maxPlayersPerGroup + "]");
|
||||
meta.setLore(lore);
|
||||
button.setItemMeta(meta);
|
||||
buttons.add(button);
|
||||
|
||||
groupCount++;
|
||||
} while (groupCount != maxGroupsPerGame);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param button the button
|
||||
* @return the matching DGroup
|
||||
*/
|
||||
public DGroup getDGroupByButton(ItemStack button) {
|
||||
int index = buttons.indexOf(button);
|
||||
if (dGroups.size() <= index || index < 0) {
|
||||
return null;
|
||||
} else {
|
||||
return dGroups.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{name=" + name + /*"; dungeon=" + dungeon + */ "}";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
|
||||
/**
|
||||
* Announcer instance manager.
|
||||
*
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerCache {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private List<Announcer> announcers = new ArrayList<>();
|
||||
|
||||
public AnnouncerCache(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void init(File folder) {
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
for (File file : folder.listFiles()) {
|
||||
addAnnouncer(new Announcer(plugin, file));
|
||||
}
|
||||
if (!announcers.isEmpty() && plugin.getMainConfig().getAnnouncmentInterval() > 0) {
|
||||
new AnnouncerTask(plugin).runTaskTimer(plugin, plugin.getMainConfig().getAnnouncmentInterval(), plugin.getMainConfig().getAnnouncmentInterval());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name
|
||||
* @return the announcer that has the name
|
||||
*/
|
||||
public Announcer getByName(String name) {
|
||||
for (Announcer announcer : announcers) {
|
||||
if (announcer.getName().equalsIgnoreCase(name)) {
|
||||
return announcer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gui the gui
|
||||
* @return the announcer that has the GUI
|
||||
*/
|
||||
public Announcer getByGUI(InventoryView gui) {
|
||||
for (Announcer announcer : announcers) {
|
||||
if ((ChatColor.DARK_RED + announcer.getName()).equals(gui.getTitle())) {
|
||||
return announcer;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the announcers
|
||||
*/
|
||||
public List<Announcer> getAnnouncers() {
|
||||
return announcers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param announcer the Announcer to add
|
||||
*/
|
||||
public void addAnnouncer(Announcer announcer) {
|
||||
announcers.add(announcer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param announcer the Announcer to remove
|
||||
*/
|
||||
public void removeAnnouncer(Announcer announcer) {
|
||||
announcers.remove(announcer);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.caliburn.category.Category;
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerListener implements Listener {
|
||||
|
||||
private AnnouncerCache announcers;
|
||||
|
||||
public AnnouncerListener(DungeonsXL plugin) {
|
||||
announcers = plugin.getAnnouncerCache();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onButtonClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
ItemStack button = event.getCurrentItem();
|
||||
Announcer announcer = announcers.getByGUI(event.getView());
|
||||
if (announcer != null && button != null && Category.WOOL.containsMaterial(button.getType())) {
|
||||
announcer.clickGroupButton(player, button);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.dungeon.Game;
|
||||
import de.erethon.dungeonsxl.api.world.GameWorld;
|
||||
import de.erethon.dungeonsxl.api.world.ResourceWorld;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.dungeon.DGame;
|
||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGroup;
|
||||
import de.erethon.dungeonsxl.util.commons.misc.ProgressBar;
|
||||
import java.util.HashSet;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerStartGameTask extends BukkitRunnable {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private Announcer announcer;
|
||||
private ProgressBar bar;
|
||||
|
||||
public AnnouncerStartGameTask(DungeonsXL plugin, Announcer announcer) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.announcer = announcer;
|
||||
HashSet<Player> players = new HashSet<>();
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
if (dGroup == null) {
|
||||
continue;
|
||||
}
|
||||
for (Player player : dGroup.getMembers().getOnlinePlayers()) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
bar = new ProgressBar(players, 30);
|
||||
bar.send(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the progress bar the players see until they get teleported
|
||||
*/
|
||||
public ProgressBar getProgressBar() {
|
||||
return bar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!announcer.areRequirementsFulfilled()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = null;
|
||||
|
||||
for (DGroup dGroup : announcer.getDGroups()) {
|
||||
if (dGroup == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dGroup.setDungeon(announcer.getDungeonName() == null ? announcer.getMapName() : announcer.getDungeonName());
|
||||
|
||||
if (game == null) {
|
||||
ResourceWorld resource = plugin.getMapRegistry().get(announcer.getMapName());
|
||||
if (resource == null) {
|
||||
dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName()));
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
game = new DGame(plugin, dGroup.getDungeon(), dGroup);
|
||||
GameWorld gameWorld = game.ensureWorldIsLoaded(false);
|
||||
if (gameWorld == null) {
|
||||
dGroup.sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
game.addGroup(dGroup);
|
||||
}
|
||||
}
|
||||
|
||||
if (game == null) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
for (Player player : game.getPlayers()) {
|
||||
new DGamePlayer(plugin, player, game.getWorld());
|
||||
}
|
||||
|
||||
announcer.endStartTask();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.announcer;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import java.util.List;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class AnnouncerTask extends BukkitRunnable {
|
||||
|
||||
private DungeonsXL plugin;
|
||||
|
||||
private List<Announcer> announcers;
|
||||
private int index;
|
||||
|
||||
public AnnouncerTask(DungeonsXL plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.announcers = plugin.getAnnouncerCache().getAnnouncers();
|
||||
index = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Announcer announcer = announcers.get(index);
|
||||
List<String> worlds = announcer.getWorlds();
|
||||
for (GlobalPlayer dPlayer : plugin.getPlayerCache()) {
|
||||
if (!(dPlayer instanceof InstancePlayer) && ((DGlobalPlayer) dPlayer).isAnnouncerEnabled()) {
|
||||
if (worlds.isEmpty() || worlds.contains(dPlayer.getPlayer().getWorld().getName())) {
|
||||
announcer.send(dPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
if (index == announcers.size()) {
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.command;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.announcer.Announcer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.api.player.InstancePlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
||||
import java.util.List;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author Goh Wei Wen
|
||||
*/
|
||||
public class AnnounceCommand extends DCommand {
|
||||
|
||||
public AnnounceCommand(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
setCommand("announce");
|
||||
setMinArgs(1);
|
||||
setMaxArgs(1);
|
||||
setHelp(DMessage.CMD_ANNOUNCE_HELP.getMessage());
|
||||
setPermission(DPermission.ANNOUNCE.getNode());
|
||||
setPlayerCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
String name = args[1];
|
||||
Announcer announcer = plugin.getAnnouncerCache().getByName(name);
|
||||
|
||||
if (announcer == null) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_ANNOUNCER.getMessage(name));
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> worlds = announcer.getWorlds();
|
||||
for (GlobalPlayer dPlayer : plugin.getPlayerCache()) {
|
||||
if (!(dPlayer instanceof InstancePlayer) && ((DGlobalPlayer) dPlayer).isAnnouncerEnabled()) {
|
||||
if (worlds.isEmpty() || worlds.contains(dPlayer.getPlayer().getWorld().getName())) {
|
||||
announcer.send(dPlayer.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -30,7 +30,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
|
||||
public static final String LABEL = "dungeonsxl";
|
||||
|
||||
public AnnounceCommand announce;
|
||||
public BreakCommand breakCmd;
|
||||
public ChatCommand chat;
|
||||
public ChatSpyCommand chatSpy;
|
||||
|
@ -45,7 +44,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
public HelpCommand help;
|
||||
public ImportCommand importCmd;
|
||||
public InviteCommand invite;
|
||||
public JoinCommand join;
|
||||
public KickCommand kick;
|
||||
public LeaveCommand leave;
|
||||
public ListCommand list;
|
||||
|
@ -65,7 +63,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
public DCommandCache(DungeonsXL plugin) {
|
||||
super(LABEL, plugin);
|
||||
|
||||
announce = new AnnounceCommand(plugin);
|
||||
breakCmd = new BreakCommand(plugin);
|
||||
chat = new ChatCommand(plugin);
|
||||
chatSpy = new ChatSpyCommand(plugin);
|
||||
|
@ -80,7 +77,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
help = new HelpCommand(plugin);
|
||||
importCmd = new ImportCommand(plugin);
|
||||
invite = new InviteCommand(plugin);
|
||||
join = new JoinCommand(plugin);
|
||||
kick = new KickCommand(plugin);
|
||||
leave = new LeaveCommand(plugin);
|
||||
list = new ListCommand(plugin);
|
||||
|
@ -97,7 +93,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
test = new TestCommand(plugin);
|
||||
uninvite = new UninviteCommand(plugin);
|
||||
|
||||
addCommand(announce);
|
||||
addCommand(breakCmd);
|
||||
addCommand(create);
|
||||
addCommand(delete);
|
||||
|
@ -112,7 +107,6 @@ public class DCommandCache extends DRECommandCache {
|
|||
addCommand(help);
|
||||
addCommand(importCmd);
|
||||
addCommand(invite);
|
||||
addCommand(join);
|
||||
addCommand(kick);
|
||||
addCommand(leave);
|
||||
addCommand(list);
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.command;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import de.erethon.dungeonsxl.announcer.Announcer;
|
||||
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
|
||||
import de.erethon.dungeonsxl.config.DMessage;
|
||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||
import de.erethon.dungeonsxl.player.DPermission;
|
||||
import de.erethon.dungeonsxl.util.commons.chat.MessageUtil;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author Daniel Saukel
|
||||
*/
|
||||
public class JoinCommand extends DCommand {
|
||||
|
||||
public JoinCommand(DungeonsXL plugin) {
|
||||
super(plugin);
|
||||
setCommand("join");
|
||||
setMinArgs(1);
|
||||
setMaxArgs(1);
|
||||
setHelp(DMessage.CMD_JOIN_HELP.getMessage());
|
||||
setPermission(DPermission.JOIN.getNode());
|
||||
setPlayerCommand(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(String[] args, CommandSender sender) {
|
||||
GlobalPlayer player = dPlayers.get((Player) sender);
|
||||
if (player instanceof DInstancePlayer) {
|
||||
MessageUtil.sendMessage(sender, DMessage.ERROR_LEAVE_GAME.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
Announcer announcer = plugin.getAnnouncerCache().getByName(args[1]);
|
||||
if (announcer != null) {
|
||||
announcer.showGUI((Player) sender);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2012-2021 Frank Baumann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.erethon.dungeonsxl.util;
|
||||
|
||||
import de.erethon.dungeonsxl.DungeonsXL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Deprecated
|
||||
public enum GUIUtil {
|
||||
|
||||
X1(4),
|
||||
X2(3, 5),
|
||||
X3(2, 4, 6),
|
||||
X4(1, 3, 5, 7),
|
||||
X5(0, 2, 4, 6, 8),
|
||||
X6(1, 2, 3, 5, 6, 7),
|
||||
X7(1, 2, 3, 4, 5, 6, 7),
|
||||
X8(0, 1, 2, 3, 5, 6, 7, 8),
|
||||
X9(0, 1, 2, 3, 4, 5, 6, 7, 8);
|
||||
|
||||
private int[] slot;
|
||||
|
||||
private GUIUtil(int... slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param count the amount of buttons
|
||||
*/
|
||||
public static GUIUtil getRowShapeByButtonCount(int count) {
|
||||
if (count >= 1 && count <= 9) {
|
||||
for (GUIUtil shape : values()) {
|
||||
if (shape.slot.length == count) {
|
||||
return shape;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin the plugin instance
|
||||
* @param title the title for the GUI
|
||||
* @param buttons the buttons to use for the GUI
|
||||
* @return an Inventory that can easily be shown to a Player
|
||||
*/
|
||||
public static Inventory createGUI(DungeonsXL plugin, String title, ItemStack... buttons) {
|
||||
return createGUI(plugin, title, Arrays.asList(buttons));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param plugin the plugin instance
|
||||
* @param title the GUI title, may contain color codes
|
||||
* @param buttons the buttons to use for the GUI
|
||||
* @return an Inventory that can easily be shown to a Player
|
||||
*/
|
||||
public static Inventory createGUI(DungeonsXL plugin, String title, List<ItemStack> buttons) {
|
||||
int rows = (int) Math.ceil(((double) buttons.size()) / 9);
|
||||
Inventory gui = plugin.getServer().createInventory(null, rows * 9, ChatColor.translateAlternateColorCodes('&', title));
|
||||
|
||||
int slot = 0;
|
||||
int row = 0;
|
||||
int i = 0;
|
||||
GUIUtil shape = null;
|
||||
|
||||
for (ItemStack button : buttons) {
|
||||
if (row + 1 == rows) {
|
||||
if (shape == null) {
|
||||
shape = getRowShapeByButtonCount(buttons.size() - i);
|
||||
}
|
||||
|
||||
gui.setItem(shape.slot[slot] + row * 9, button);
|
||||
slot++;
|
||||
|
||||
} else {
|
||||
gui.setItem(X9.slot[slot] + row * 9, button);
|
||||
|
||||
slot++;
|
||||
if (slot == 9) {
|
||||
slot = 0;
|
||||
row++;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
plugin.getGUIs().add(gui);
|
||||
return gui;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue