forked from SteamWar/SteamWar
Remove TutorialSystem
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2023 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.sql;
|
||||
|
||||
import de.steamwar.sql.internal.Field;
|
||||
import de.steamwar.sql.internal.SelectStatement;
|
||||
import de.steamwar.sql.internal.Statement;
|
||||
import de.steamwar.sql.internal.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class Tutorial {
|
||||
|
||||
private static final Table<Tutorial> table = new Table<>(Tutorial.class);
|
||||
private static final SelectStatement<Tutorial> by_popularity = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Released = ? GROUP BY t.TutorialID ORDER BY SUM(r.Stars) DESC LIMIT ?, ?");
|
||||
private static final SelectStatement<Tutorial> own = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? GROUP BY t.TutorialID ORDER BY t.TutorialID ASC LIMIT ?, ?");
|
||||
private static final SelectStatement<Tutorial> by_creator_name = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.Creator = ? AND t.Name = ? GROUP BY t.TutorialID");
|
||||
private static final SelectStatement<Tutorial> by_id = new SelectStatement<>(table, "SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID WHERE t.TutorialID = ? GROUP BY t.TutorialID");
|
||||
private static final Statement rate = new Statement("INSERT INTO TutorialRating (TutorialID, UserID, Stars) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Stars = VALUES(Stars)");
|
||||
private static final Statement create = new Statement("INSERT INTO Tutorial (Creator, Name, Item) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), Released = 0");
|
||||
private static final Statement release = table.update(Table.PRIMARY, "released");
|
||||
private static final Statement delete = table.delete(Table.PRIMARY);
|
||||
|
||||
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
|
||||
List<Tutorial> tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage);
|
||||
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
|
||||
return tutorials;
|
||||
}
|
||||
|
||||
public static List<Tutorial> getOwn(int user, int page, int elementsPerPage) {
|
||||
return own.listSelect(user, page * elementsPerPage, elementsPerPage);
|
||||
}
|
||||
|
||||
public static Tutorial create(int creator, String name, String item) {
|
||||
create.update(creator, name, item);
|
||||
return by_creator_name.select(creator, name);
|
||||
}
|
||||
|
||||
public static Tutorial get(int id) {
|
||||
return by_id.select(id);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Field(keys = {Table.PRIMARY}, autoincrement = true)
|
||||
private final int tutorialId;
|
||||
@Getter
|
||||
@Field(keys = {"CreatorName"})
|
||||
private final int creator;
|
||||
@Getter
|
||||
@Field(keys = {"CreatorName"})
|
||||
private final String name;
|
||||
@Getter
|
||||
@Field(def = "'BOOK'")
|
||||
private final String item;
|
||||
@Getter
|
||||
@Field(def = "0")
|
||||
private final boolean released;
|
||||
@Getter
|
||||
@Field(def = "0") // Not really a field, but necessary for select generation
|
||||
private final double stars;
|
||||
|
||||
public void release() {
|
||||
release.update(1, tutorialId);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
delete.update(tutorialId);
|
||||
}
|
||||
|
||||
public void rate(int user, int rating) {
|
||||
rate.update(tutorialId, user, rating);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2024 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/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
steamwar.java
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":SpigotCore", "default"))
|
||||
|
||||
compileOnly(libs.nms15)
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.tutorial;
|
||||
|
||||
import de.steamwar.tutorial.commands.BookReplaceCommand;
|
||||
import de.steamwar.tutorial.commands.TutorialCommand;
|
||||
import de.steamwar.tutorial.commands.UnsignCommand;
|
||||
import de.steamwar.tutorial.listener.Joining;
|
||||
import de.steamwar.tutorial.listener.RateSign;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class TutorialSystem extends JavaPlugin {
|
||||
|
||||
private static TutorialSystem plugin;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
new RateSign();
|
||||
new Joining();
|
||||
|
||||
new BookReplaceCommand();
|
||||
new TutorialCommand();
|
||||
new UnsignCommand();
|
||||
}
|
||||
|
||||
public static TutorialSystem getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package de.steamwar.tutorial.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BookReplaceCommand extends SWCommand {
|
||||
|
||||
public BookReplaceCommand() {
|
||||
super("bookreplace");
|
||||
}
|
||||
|
||||
@Register("color")
|
||||
public void color(Player player) {
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta instanceof BookMeta) {
|
||||
BookMeta bookMeta = (BookMeta) itemMeta;
|
||||
replace(bookMeta, '&', '§');
|
||||
itemStack.setItemMeta(bookMeta);
|
||||
player.getInventory().setItemInMainHand(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Register("uncolor")
|
||||
public void uncolor(Player player) {
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta instanceof BookMeta) {
|
||||
BookMeta bookMeta = (BookMeta) itemMeta;
|
||||
replace(bookMeta, '§', '&');
|
||||
itemStack.setItemMeta(bookMeta);
|
||||
player.getInventory().setItemInMainHand(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
private void replace(BookMeta bookMeta, char oldChar, char newChar) {
|
||||
List<String> stringList = bookMeta.getPages();
|
||||
for (int i = 0; i < stringList.size(); i++) {
|
||||
String string = stringList.get(i);
|
||||
bookMeta.setPage(i + 1, string.replace(oldChar, newChar));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package de.steamwar.tutorial.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.network.NetworkSender;
|
||||
import de.steamwar.network.packets.client.ExecuteCommandPacket;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class TutorialCommand extends SWCommand {
|
||||
|
||||
public TutorialCommand() {
|
||||
super("tutorial");
|
||||
}
|
||||
|
||||
@Register("rate")
|
||||
public void rateCommand(Player player) {
|
||||
rate(player);
|
||||
}
|
||||
|
||||
public static void rate(Player player) {
|
||||
NetworkSender.send(new ExecuteCommandPacket(SteamwarUser.get(player.getUniqueId()).getId(), "tutorial rate " + System.getProperty("tutorial")));
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package de.steamwar.tutorial.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class UnsignCommand extends SWCommand {
|
||||
|
||||
public UnsignCommand() {
|
||||
super("unsign");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void unsignCommand(Player p) {
|
||||
ItemStack itemStack = p.getInventory().getItemInMainHand();
|
||||
if (itemStack.getType() != Material.WRITTEN_BOOK) return;
|
||||
itemStack.setType(Material.WRITABLE_BOOK);
|
||||
p.getInventory().setItemInMainHand(itemStack);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.tutorial.listener;
|
||||
|
||||
import de.steamwar.tutorial.TutorialSystem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class BasicListener implements Listener {
|
||||
|
||||
public BasicListener() {
|
||||
Bukkit.getPluginManager().registerEvents(this, TutorialSystem.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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.tutorial.listener;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class Joining extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
event.getPlayer().setOp(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
if (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) {
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* 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.tutorial.listener;
|
||||
|
||||
import de.steamwar.tutorial.commands.TutorialCommand;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
public class RateSign extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
if(!event.hasBlock() || event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
||||
return;
|
||||
|
||||
BlockState state = event.getClickedBlock().getState();
|
||||
if (!(state instanceof Sign))
|
||||
return;
|
||||
|
||||
Sign sign = (Sign) state;
|
||||
if(!"[rate]".equals(sign.getLine(0)))
|
||||
return;
|
||||
|
||||
Player player = event.getPlayer();
|
||||
TutorialCommand.rate(player);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
name: TutorialSystem
|
||||
version: "1.0"
|
||||
authors:
|
||||
- Lixfel
|
||||
main: de.steamwar.tutorial.TutorialSystem
|
||||
depend: [SpigotCore]
|
||||
api-version: "1.13"
|
||||
@@ -52,7 +52,6 @@ public class ServerStarter {
|
||||
public static final String TEMP_WORLD_PATH = TMP_DATA + "arenaserver/";
|
||||
|
||||
private static final String WORLDS_FOLDER = "/worlds";
|
||||
public static final String TUTORIAL_PATH = WORLDS_FOLDER + "/tutorials/";
|
||||
public static final String WORLDS_BASE_PATH = WORLDS_FOLDER + "/userworlds";
|
||||
public static final String BUILDER_BASE_PATH = WORLDS_FOLDER + "/builder";
|
||||
|
||||
@@ -194,15 +193,6 @@ public class ServerStarter {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerStarter tutorial(Player owner, Tutorial tutorial) {
|
||||
version = ServerVersion.SPIGOT_15;
|
||||
directory = new File(SERVER_PATH, "Tutorial");
|
||||
buildWithTemp(owner);
|
||||
tempWorld(TUTORIAL_PATH + tutorial.getTutorialId());
|
||||
arguments.put("tutorial", String.valueOf(tutorial.getTutorialId()));
|
||||
return send(owner);
|
||||
}
|
||||
|
||||
private void tempWorld(String template) {
|
||||
worldDir = TEMP_WORLD_PATH;
|
||||
worldSetup = () -> copyWorld(node, template, worldDir + worldName);
|
||||
|
||||
@@ -215,7 +215,6 @@ public class VelocityCore implements ReloadablePlugin {
|
||||
new ChallengeCommand();
|
||||
new HistoricCommand();
|
||||
new ReplayCommand();
|
||||
new TutorialCommand();
|
||||
|
||||
new Broadcaster();
|
||||
new CookieEvents();
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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.velocitycore.commands;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeValidator;
|
||||
import de.steamwar.messages.Chatter;
|
||||
import de.steamwar.messages.Message;
|
||||
import de.steamwar.messages.PlayerChatter;
|
||||
import de.steamwar.persistent.Subserver;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import de.steamwar.sql.Tutorial;
|
||||
import de.steamwar.sql.UserPerm;
|
||||
import de.steamwar.velocitycore.ServerStarter;
|
||||
import de.steamwar.velocitycore.SubserverSystem;
|
||||
import de.steamwar.velocitycore.VelocityCore;
|
||||
import de.steamwar.velocitycore.inventory.SWInventory;
|
||||
import de.steamwar.velocitycore.inventory.SWItem;
|
||||
import de.steamwar.velocitycore.inventory.SWListInv;
|
||||
import de.steamwar.velocitycore.inventory.SWStreamInv;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TutorialCommand extends SWCommand {
|
||||
|
||||
public TutorialCommand() {
|
||||
super("tutorial");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void genericCommand(PlayerChatter sender) {
|
||||
openInventory(sender, true, false);
|
||||
}
|
||||
|
||||
@Register("rate")
|
||||
public void rate(PlayerChatter sender) {
|
||||
sender.getPlayer().spoofChatInput("/tutorial rate");
|
||||
}
|
||||
|
||||
@Register("rate")
|
||||
public void rate(PlayerChatter sender, int id) {
|
||||
Tutorial tutorial = Tutorial.get(id);
|
||||
if(tutorial == null) {
|
||||
sender.getPlayer().spoofChatInput("/tutorial rate"); // Catch players manually entering numbers
|
||||
return;
|
||||
}
|
||||
|
||||
rate(sender, tutorial);
|
||||
}
|
||||
|
||||
@Register(value = "create", description = "TUTORIAL_CREATE_HELP")
|
||||
public void create(PlayerChatter sender, String material, String... name) {
|
||||
create(sender, String.join(" ", name), material.toUpperCase());
|
||||
}
|
||||
|
||||
@Register("own")
|
||||
public void own(PlayerChatter sender) {
|
||||
openInventory(sender, false, true);
|
||||
}
|
||||
|
||||
@Register("unreleased")
|
||||
public void unreleased(@Validator("unreleased") PlayerChatter sender) {
|
||||
openInventory(sender, false, false);
|
||||
}
|
||||
|
||||
@Validator("unreleased")
|
||||
public TypeValidator<Chatter> unreleasedChecker() {
|
||||
return (sender, value, messageSender) -> sender.user().hasPerm(UserPerm.TEAM);
|
||||
}
|
||||
|
||||
private void openInventory(PlayerChatter sender, boolean released, boolean own) {
|
||||
SteamwarUser user = sender.user();
|
||||
|
||||
new SWStreamInv<>(
|
||||
sender,
|
||||
new Message("TUTORIAL_TITLE"),
|
||||
(click, tutorial) -> {
|
||||
if(!released && click.isShiftClick() && user.hasPerm(UserPerm.TEAM) && user.getId() != tutorial.getCreator()) {
|
||||
tutorial.release();
|
||||
openInventory(sender, released, own);
|
||||
return;
|
||||
} else if(own && click.isShiftClick() && click.isRightClick()) {
|
||||
tutorial.delete();
|
||||
SubserverSystem.deleteFolder(VelocityCore.local, world(tutorial).getPath());
|
||||
openInventory(sender, released, own);
|
||||
return;
|
||||
}
|
||||
|
||||
new ServerStarter().tutorial(sender.getPlayer(), tutorial).start();
|
||||
},
|
||||
page -> (own ? Tutorial.getOwn(user.getId(), page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(tutorial, own), tutorial)).toList()
|
||||
).open();
|
||||
}
|
||||
|
||||
private SWItem getTutorialItem(Tutorial tutorial, boolean personalHighlights) {
|
||||
SWItem item = new SWItem(tutorial.getItem(), new Message("TUTORIAL_NAME", tutorial.getName()));
|
||||
item.setHideAttributes(true);
|
||||
|
||||
item.addLore(new Message("TUTORIAL_BY", SteamwarUser.get(tutorial.getCreator()).getUserName()));
|
||||
item.addLore(new Message("TUTORIAL_STARS", String.format("%.1f", tutorial.getStars())));
|
||||
|
||||
if (personalHighlights)
|
||||
item.addLore(new Message("TUTORIAL_DELETE"));
|
||||
|
||||
if (personalHighlights && tutorial.isReleased())
|
||||
item.setEnchanted(true);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private void rate(PlayerChatter sender, Tutorial tutorial) {
|
||||
int[] rates = new int[]{1, 2, 3, 4, 5};
|
||||
|
||||
new SWListInv<>(sender, new Message("TUTORIAL_RATE_TITLE"), Arrays.stream(rates).mapToObj(rate -> new SWListInv.SWListEntry<>(new SWItem("NETHER_STAR", new Message("TUTORIAL_RATE", rate)), rate)).toList(), (click, rate) -> {
|
||||
tutorial.rate(sender.user().getId(), rate);
|
||||
SWInventory.close(sender);
|
||||
}).open();
|
||||
}
|
||||
|
||||
private void create(PlayerChatter sender, String name, String item) {
|
||||
Subserver subserver = Subserver.getSubserver(sender.getPlayer());
|
||||
SteamwarUser user = sender.user();
|
||||
File tempWorld = new File(ServerStarter.TEMP_WORLD_PATH, ServerStarter.serverToWorldName(ServerStarter.bauServerName(user)));
|
||||
|
||||
if(!Subserver.isBuild(subserver) || !subserver.isStarted() || !tempWorld.exists()) {
|
||||
sender.system("TUTORIAL_CREATE_MISSING");
|
||||
return;
|
||||
}
|
||||
|
||||
subserver.execute("save-all");
|
||||
VelocityCore.schedule(() -> {
|
||||
Tutorial tutorial = Tutorial.create(user.getId(), name, item);
|
||||
File tutorialWorld = world(tutorial);
|
||||
|
||||
if (tutorialWorld.exists())
|
||||
SubserverSystem.deleteFolder(VelocityCore.local, tutorialWorld.getPath());
|
||||
ServerStarter.copyWorld(VelocityCore.local, tempWorld.getPath(), tutorialWorld.getPath());
|
||||
sender.system("TUTORIAL_CREATED");
|
||||
}).delay(1, TimeUnit.SECONDS).schedule();
|
||||
}
|
||||
|
||||
private File world(Tutorial tutorial) {
|
||||
return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.getTutorialId()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user