Archiviert
1
0

Merge pull request 'Tutorial deletion option' (#320) from tutorialDeletion into master

Reviewed-on: SteamWar/BungeeCore#320
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-22 16:47:55 +01:00
Commit d7ec665dc2
3 geänderte Dateien mit 82 neuen und 64 gelöschten Zeilen

Datei anzeigen

@ -26,14 +26,15 @@ import de.steamwar.bungeecore.inventory.SWListInv;
import de.steamwar.bungeecore.inventory.SWStreamInv; import de.steamwar.bungeecore.inventory.SWStreamInv;
import de.steamwar.bungeecore.sql.SteamwarUser; import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.Tutorial; import de.steamwar.bungeecore.sql.Tutorial;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -49,57 +50,54 @@ public class TutorialCommand extends BasicCommand {
return; return;
ProxiedPlayer player = (ProxiedPlayer) sender; ProxiedPlayer player = (ProxiedPlayer) sender;
if(args.length != 0) { if(args.length == 0) {
switch(args[0].toLowerCase()) { openInventory(player, true, false);
case "rate":
if(args.length < 2) {
player.chat("/tutorial rate");
return;
}
int id;
try {
id = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with non number: " + args[1]);
return;
}
Tutorial tutorial = Tutorial.get(id);
if(tutorial == null) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id);
return;
}
rate(player, tutorial);
break;
case "create":
if(args.length < 3) {
Message.send("TUTORIAL_CREATE_HELP", player);
return;
}
String material = args[1].toUpperCase();
String name = Arrays.stream(args).skip(2).collect(Collectors.joining(" "));
create(player, name, material);
break;
case "own":
openInventory(player, false, true);
break;
case "unreleased":
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) {
openInventory(player, false, false);
break;
}
default:
Message.send("TUTORIAL_CREATE_HELP", player);
Message.send("TUTORIAL_OWN_HELP", player);
}
return; return;
} }
openInventory(player, true, false); switch(args[0].toLowerCase()) {
case "rate":
if(args.length < 2) {
player.chat("/tutorial rate");
return;
}
int id;
try {
id = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with non number: " + args[1]);
return;
}
Tutorial tutorial = Tutorial.get(id);
if(tutorial == null) {
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with nonexistent id: " + id);
return;
}
rate(player, tutorial);
break;
case "create":
if(args.length < 3) {
Message.send("TUTORIAL_CREATE_HELP", player);
return;
}
create(player, Arrays.stream(args).skip(2).collect(Collectors.joining(" ")), args[1].toUpperCase());
break;
case "own":
openInventory(player, false, true);
break;
case "unreleased":
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) {
openInventory(player, false, false);
break;
}
default:
Message.send("TUTORIAL_CREATE_HELP", player);
Message.send("TUTORIAL_OWN_HELP", player);
}
} }
private void openInventory(ProxiedPlayer player, boolean released, boolean own) { private void openInventory(ProxiedPlayer player, boolean released, boolean own) {
@ -111,6 +109,11 @@ public class TutorialCommand extends BasicCommand {
(click, tutorial) -> { (click, tutorial) -> {
if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user != tutorial.creator()) { if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user != tutorial.creator()) {
tutorial.release(); tutorial.release();
openInventory(player, released, own);
return;
} else if(own && click.isShiftClick() && click.isRightClick()) {
tutorial.delete();
openInventory(player, released, own);
return; return;
} }
@ -120,16 +123,20 @@ public class TutorialCommand extends BasicCommand {
).open(); ).open();
} }
private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean highlightReleased) { private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean personalHighlights) {
SWItem item = new SWItem(tutorial.item(), Message.parse("TUTORIAL_NAME", player, tutorial.name())); SWItem item = new SWItem(tutorial.item(), Message.parse("TUTORIAL_NAME", player, tutorial.name()));
item.setHideAttributes(true); item.setHideAttributes(true);
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
lore.add(Message.parse("TUTORIAL_BY", player, tutorial.creator().getUserName())); lore.add(Message.parse("TUTORIAL_BY", player, tutorial.creator().getUserName()));
lore.add(Message.parse("TUTORIAL_STARS", player, tutorial.stars())); lore.add(Message.parse("TUTORIAL_STARS", player, tutorial.stars()));
if (personalHighlights)
lore.add(Message.parse("TUTORIAL_DELETE", player));
item.setLore(lore); item.setLore(lore);
if (highlightReleased && tutorial.released()) if (personalHighlights && tutorial.released())
item.setEnchanted(true); item.setEnchanted(true);
return item; return item;
@ -156,19 +163,14 @@ public class TutorialCommand extends BasicCommand {
} }
subserver.execute("save-all"); subserver.execute("save-all");
try { ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
Thread.sleep(1000); Tutorial tutorial = Tutorial.create(user, name, item);
} catch (InterruptedException e) { File tutorialWorld = tutorial.world();
BungeeCore.get().getLogger().log(Level.WARNING, "Tutorial creation interrupted", e);
Thread.currentThread().interrupt();
}
Tutorial tutorial = Tutorial.create(user, name, item); if (tutorialWorld.exists())
File tutorialWorld = new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.id())); SubserverSystem.deleteFolder(Node.local, tutorialWorld.getPath());
ServerStarter.copyWorld(Node.local, tempWorld.getPath(), tutorialWorld.getPath());
if (tutorialWorld.exists()) Message.send("TUTORIAL_CREATED", player);
SubserverSystem.deleteFolder(Node.local, tutorialWorld.getPath()); }, 1, TimeUnit.SECONDS);
ServerStarter.copyWorld(Node.local, tempWorld.getPath(), tutorialWorld.getPath());
Message.send("TUTORIAL_CREATED", player);
} }
} }

Datei anzeigen

@ -19,6 +19,11 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.Node;
import de.steamwar.bungeecore.ServerStarter;
import de.steamwar.bungeecore.SubserverSystem;
import java.io.File;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,6 +39,7 @@ public class Tutorial {
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 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 create = new Statement("INSERT INTO Tutorial (Creator, Name, Item) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Item = VALUES(Item), Released = 0");
private static final Statement release = new Statement("UPDATE Tutorial SET Released = 1 WHERE TutorialID = ?"); private static final Statement release = new Statement("UPDATE Tutorial SET Released = 1 WHERE TutorialID = ?");
private static final Statement delete = new Statement("DELETE FROM Tutorial WHERE TutorialID = ?");
public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) { public static List<Tutorial> getPage(int page, int elementsPerPage, boolean released) {
List<Tutorial> tutorials = by_popularity.select(rs -> { List<Tutorial> tutorials = by_popularity.select(rs -> {
@ -116,6 +122,15 @@ public class Tutorial {
release.update(id); release.update(id);
} }
public void delete() {
delete.update(id);
SubserverSystem.deleteFolder(Node.local, world().getPath());
}
public File world() {
return new File(ServerStarter.TUTORIAL_PATH, String.valueOf(id));
}
public void rate(SteamwarUser user, int rating) { public void rate(SteamwarUser user, int rating) {
rate.update(id, user.getId(), rating); rate.update(id, user.getId(), rating);
} }

Datei anzeigen

@ -340,6 +340,7 @@ TUTORIAL_BY=§8von §7{0}
TUTORIAL_STARS=§e{0} §7Sterne TUTORIAL_STARS=§e{0} §7Sterne
TUTORIAL_RATE_TITLE=Tutorial bewerten TUTORIAL_RATE_TITLE=Tutorial bewerten
TUTORIAL_RATE=§e{0} §7Stern(e) TUTORIAL_RATE=§e{0} §7Stern(e)
TUTORIAL_DELETE=§cMit Shift+Rechtsklick löschen
TUTORIAL_CREATE_HELP=§8/§7tutorial create §8[§eMaterial§8] §8[§eName§8] TUTORIAL_CREATE_HELP=§8/§7tutorial create §8[§eMaterial§8] §8[§eName§8]
TUTORIAL_CREATE_MISSING=§cEin Tutorial kann nur von einem Tutorialserver aus erstellt werden! TUTORIAL_CREATE_MISSING=§cEin Tutorial kann nur von einem Tutorialserver aus erstellt werden!
TUTORIAL_CREATED=§7Das Tutorial wurde erstellt§8. TUTORIAL_CREATED=§7Das Tutorial wurde erstellt§8.