geforkt von SteamWar/BungeeCore
Tutorial deletion option
Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
cca097b7ef
Commit
c380bd82d3
@ -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,7 +50,11 @@ public class TutorialCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
if(args.length != 0) {
|
if(args.length == 0) {
|
||||||
|
openInventory(player, true, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch(args[0].toLowerCase()) {
|
switch(args[0].toLowerCase()) {
|
||||||
case "rate":
|
case "rate":
|
||||||
if(args.length < 2) {
|
if(args.length < 2) {
|
||||||
@ -79,14 +84,11 @@ public class TutorialCommand extends BasicCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String material = args[1].toUpperCase();
|
create(player, Arrays.stream(args).skip(2).collect(Collectors.joining(" ")), args[1].toUpperCase());
|
||||||
String name = Arrays.stream(args).skip(2).collect(Collectors.joining(" "));
|
|
||||||
create(player, name, material);
|
|
||||||
break;
|
break;
|
||||||
case "own":
|
case "own":
|
||||||
openInventory(player, false, true);
|
openInventory(player, false, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "unreleased":
|
case "unreleased":
|
||||||
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) {
|
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) {
|
||||||
openInventory(player, false, false);
|
openInventory(player, false, false);
|
||||||
@ -96,10 +98,6 @@ public class TutorialCommand extends BasicCommand {
|
|||||||
Message.send("TUTORIAL_CREATE_HELP", player);
|
Message.send("TUTORIAL_CREATE_HELP", player);
|
||||||
Message.send("TUTORIAL_OWN_HELP", player);
|
Message.send("TUTORIAL_OWN_HELP", player);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
openInventory(player, true, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
BungeeCore.get().getLogger().log(Level.WARNING, "Tutorial creation interrupted", e);
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tutorial tutorial = Tutorial.create(user, name, item);
|
Tutorial tutorial = Tutorial.create(user, name, item);
|
||||||
File tutorialWorld = new File(ServerStarter.TUTORIAL_PATH, String.valueOf(tutorial.id()));
|
File tutorialWorld = tutorial.world();
|
||||||
|
|
||||||
if (tutorialWorld.exists())
|
if (tutorialWorld.exists())
|
||||||
SubserverSystem.deleteFolder(Node.local, tutorialWorld.getPath());
|
SubserverSystem.deleteFolder(Node.local, tutorialWorld.getPath());
|
||||||
ServerStarter.copyWorld(Node.local, tempWorld.getPath(), tutorialWorld.getPath());
|
ServerStarter.copyWorld(Node.local, tempWorld.getPath(), tutorialWorld.getPath());
|
||||||
Message.send("TUTORIAL_CREATED", player);
|
Message.send("TUTORIAL_CREATED", player);
|
||||||
|
}, 1, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren