Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Ursprung
e2fd1754ce
Commit
364422af2f
@ -49,7 +49,7 @@ public class TutorialCommand extends BasicCommand {
|
|||||||
ProxiedPlayer player = (ProxiedPlayer) sender;
|
ProxiedPlayer player = (ProxiedPlayer) sender;
|
||||||
|
|
||||||
if(args.length != 0) {
|
if(args.length != 0) {
|
||||||
switch(args[0]) {
|
switch(args[0].toLowerCase()) {
|
||||||
case "rate":
|
case "rate":
|
||||||
if(args.length < 2) {
|
if(args.length < 2) {
|
||||||
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with missing argument");
|
BungeeCore.get().getLogger().log(Level.SEVERE, "rate executed with missing argument");
|
||||||
@ -82,23 +82,55 @@ public class TutorialCommand extends BasicCommand {
|
|||||||
String name = Arrays.stream(args).skip(2).collect(Collectors.joining(" "));
|
String name = Arrays.stream(args).skip(2).collect(Collectors.joining(" "));
|
||||||
create(player, name, material);
|
create(player, name, material);
|
||||||
break;
|
break;
|
||||||
|
case "own":
|
||||||
|
openInventory(player, false, true);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "unreleased":
|
||||||
|
if (SteamwarUser.get(player.getUniqueId()).getUserGroup().isTeamGroup()) {
|
||||||
|
openInventory(player, false, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Message.send("TUTORIAL_CREATE_HELP", player);
|
Message.send("TUTORIAL_CREATE_HELP", player);
|
||||||
|
Message.send("TUTORIAL_OWN_HELP", player);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new SWStreamInv<>(player, Message.parse("TUTORIAL_TITLE", player), (click, tutorial) -> new ServerStarter().tutorial(player, tutorial).start(), page -> Tutorial.getPage(page, 45).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial), tutorial)).collect(Collectors.toList())).open();
|
openInventory(player, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial) {
|
private void openInventory(ProxiedPlayer player, boolean released, boolean own) {
|
||||||
|
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
|
||||||
|
|
||||||
|
new SWStreamInv<>(
|
||||||
|
player,
|
||||||
|
Message.parse("TUTORIAL_TITLE", player),
|
||||||
|
(click, tutorial) -> {
|
||||||
|
if(!released && click.isShiftClick() && user.getUserGroup().isTeamGroup() && user != tutorial.creator()) {
|
||||||
|
tutorial.release();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new ServerStarter().tutorial(player, tutorial).start();
|
||||||
|
},
|
||||||
|
page -> (own ? Tutorial.getOwn(user, page, 45) : Tutorial.getPage(page, 45, released)).stream().map(tutorial -> new SWListInv.SWListEntry<>(getTutorialItem(player, tutorial, own), tutorial)).collect(Collectors.toList())
|
||||||
|
).open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private SWItem getTutorialItem(ProxiedPlayer player, Tutorial tutorial, boolean highlightReleased) {
|
||||||
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);
|
||||||
|
|
||||||
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()));
|
||||||
item.setLore(lore);
|
item.setLore(lore);
|
||||||
|
|
||||||
|
if (highlightReleased && tutorial.released())
|
||||||
|
item.setEnchanted(true);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,24 +27,35 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class Tutorial {
|
public class Tutorial {
|
||||||
|
|
||||||
private static final Statement by_popularity = new Statement("SELECT t.*, AVG(r.Stars) AS Stars FROM Tutorial t LEFT OUTER JOIN TutorialRating r ON t.TutorialID = r.TutorialID GROUP BY t.TutorialID ORDER BY SUM(r.Stars) DESC LIMIT ?, ?");
|
private static final Statement by_popularity = new Statement("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 Statement own = new Statement("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 Statement by_creator_name = new Statement("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 Statement by_creator_name = new Statement("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 Statement by_id = new Statement("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 by_id = new Statement("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 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)");
|
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 = ?");
|
||||||
|
|
||||||
public static List<Tutorial> getPage(int page, int elementsPerPage) {
|
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 -> {
|
||||||
List<Tutorial> t = new ArrayList<>();
|
List<Tutorial> t = new ArrayList<>();
|
||||||
while(rs.next())
|
while(rs.next())
|
||||||
t.add(new Tutorial(rs));
|
t.add(new Tutorial(rs));
|
||||||
return t;
|
return t;
|
||||||
}, page * elementsPerPage, elementsPerPage);
|
}, released, page * elementsPerPage, elementsPerPage);
|
||||||
|
|
||||||
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
|
SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet()));
|
||||||
return tutorials;
|
return tutorials;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Tutorial> getOwn(SteamwarUser user, int page, int elementsPerPage) {
|
||||||
|
return own.select(rs -> {
|
||||||
|
List<Tutorial> t = new ArrayList<>();
|
||||||
|
while(rs.next())
|
||||||
|
t.add(new Tutorial(rs));
|
||||||
|
return t;
|
||||||
|
}, user.getId(), page * elementsPerPage, elementsPerPage);
|
||||||
|
}
|
||||||
|
|
||||||
public static Tutorial create(SteamwarUser creator, String name, String item) {
|
public static Tutorial create(SteamwarUser creator, String name, String item) {
|
||||||
create.update(creator.getId(), name, item);
|
create.update(creator.getId(), name, item);
|
||||||
return by_creator_name.select(rs -> {
|
return by_creator_name.select(rs -> {
|
||||||
@ -66,12 +77,14 @@ public class Tutorial {
|
|||||||
private final String name;
|
private final String name;
|
||||||
private final String item;
|
private final String item;
|
||||||
private final double stars;
|
private final double stars;
|
||||||
|
private final boolean released;
|
||||||
|
|
||||||
public Tutorial(ResultSet rs) throws SQLException {
|
public Tutorial(ResultSet rs) throws SQLException {
|
||||||
this.id = rs.getInt("TutorialID");
|
this.id = rs.getInt("TutorialID");
|
||||||
this.creator = rs.getInt("Creator");
|
this.creator = rs.getInt("Creator");
|
||||||
this.name = rs.getString("Name");
|
this.name = rs.getString("Name");
|
||||||
this.item = rs.getString("Item");
|
this.item = rs.getString("Item");
|
||||||
|
this.released = rs.getBoolean("Released");
|
||||||
this.stars = rs.getDouble("Stars");
|
this.stars = rs.getDouble("Stars");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +108,14 @@ public class Tutorial {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean released() {
|
||||||
|
return released;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void release() {
|
||||||
|
release.update(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);
|
||||||
}
|
}
|
||||||
|
@ -343,6 +343,7 @@ TUTORIAL_RATE=§e{0} §7Stern(e)
|
|||||||
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.
|
||||||
|
TUTORIAL_OWN_HELP=§8/§7tutorial own §8- §7Liste der eigenen Tutorials
|
||||||
|
|
||||||
#ServerTeamchatCommand
|
#ServerTeamchatCommand
|
||||||
STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8]
|
STC_USAGE=§8/§7stc §8[§eNachricht an das Team§8]
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren