forked from SteamWar/SteamWar
Add BauSystem module
Fix ci java version Fix LinkageProcessor
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.inventory.SWListInv;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class AdventCommand extends SWCommand {
|
||||
|
||||
public AdventCommand() {
|
||||
super("advent", "calendar", "adventcalendar");
|
||||
}
|
||||
|
||||
// @Register
|
||||
/*
|
||||
public void show(Player player, @Min(intValue = 1) @Max(intValue = 31) int day) {
|
||||
if (SteamwarUser.get(player.getUniqueId()).getUserGroup() == UserGroup.Member) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.removePlayer(player);
|
||||
if (day == present.getDay()) {
|
||||
present.addPlayer(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
@Register
|
||||
public void genericCommand(Player player, String... args) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
List<SWListInv.SWListEntry<Present>> itemList = new ArrayList<>();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
NodeMember nodeMember = NodeMember.getNodeMember(present.getSchematicId(), steamwarUser.getId());
|
||||
SWItem item;
|
||||
if (nodeMember == null) {
|
||||
item = SWItem.getPlayerSkull(random.nextBoolean() ? "MHF_Present1" : "MHF_Present2");
|
||||
} else {
|
||||
item = new SWItem(Material.CHEST, "");
|
||||
}
|
||||
item.setName(LobbySystem.getMessage().parse("ADVENT_CALENDAR_DAY", player, present.getDay()));
|
||||
itemList.add(new SWListInv.SWListEntry<>(item, present));
|
||||
});
|
||||
SWInventory swInventory = new SWInventory(player, 27, LobbySystem.getMessage().parse("ADVENT_CALENDAR_TITLE", player));
|
||||
for (int i = 0; i < itemList.size(); i++) {
|
||||
swInventory.setItem(i, itemList.get(i).getItem());
|
||||
}
|
||||
swInventory.open();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class AdventListener extends BasicListener {
|
||||
|
||||
public static final int ADVENT_SLOT = 7;
|
||||
public static final SWItem ADVENT = SWItem.getPlayerSkull("MHF_Present1");
|
||||
static {
|
||||
ADVENT.setName("§fAdvent");
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handlePlayerInteract(PlayerInteractEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
if(item == null)
|
||||
return;
|
||||
|
||||
if (item.getType() == Material.PLAYER_HEAD && item.getItemMeta() != null && item.getItemMeta().getDisplayName().equals("§fAdvent")) {
|
||||
event.getPlayer().performCommand("advent");
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
e.getPlayer().getInventory().setItem(ADVENT_SLOT, ADVENT.getItemStack());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AdventsCalendar {
|
||||
|
||||
private static List<Present> presentList = new ArrayList<>();
|
||||
|
||||
private static File file = new File(LobbySystem.getPlugin().getDataFolder(), "presents.yml");
|
||||
private static FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
public static void init() {
|
||||
new AdventCommand();
|
||||
new AdventListener();
|
||||
new PresentClickListener();
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 1; i <= 31; i++) {
|
||||
if (i > 24 && i < 31) continue;
|
||||
ConfigurationSection section = fileConfiguration.getConfigurationSection(i + "");
|
||||
if (section == null) {
|
||||
section = fileConfiguration.createSection(i + "");
|
||||
}
|
||||
presentList.add(new Present(i, section));
|
||||
if (i == 24) {
|
||||
presentList.add(new Present(25, section));
|
||||
presentList.add(new Present(26, section));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Present> getPresentList() {
|
||||
return presentList;
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
fileConfiguration.save(file);
|
||||
} catch (IOException e) {
|
||||
// Ignore
|
||||
}
|
||||
System.out.println("Save time: " + (System.currentTimeMillis() - time) + "ms");
|
||||
}
|
||||
|
||||
public static boolean active() {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
Month month = localDate.getMonth();
|
||||
return month == Month.DECEMBER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SchematicNode;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Present {
|
||||
|
||||
private static final World WORLD = Bukkit.getWorlds().get(0);
|
||||
|
||||
@Data
|
||||
private static class Point {
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
public static Point toPoint(Location location) {
|
||||
return new Point(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
}
|
||||
}
|
||||
|
||||
private final List<Map<String, Integer>> blockList;
|
||||
private final Set<Point> locations = new HashSet<>();
|
||||
|
||||
@Getter
|
||||
private final int day;
|
||||
|
||||
@Getter
|
||||
private final int schematicId;
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
|
||||
public Present(int day, ConfigurationSection configurationSection) {
|
||||
this.day = day;
|
||||
if (configurationSection.contains("schematicId")) {
|
||||
schematicId = configurationSection.getInt("schematicId");
|
||||
} else {
|
||||
configurationSection.set("schematicId", -1);
|
||||
schematicId = -1;
|
||||
}
|
||||
List<?> blockList = configurationSection.getList("blocks");
|
||||
if (blockList == null) {
|
||||
blockList = new ArrayList<>();
|
||||
configurationSection.set("blocks", blockList);
|
||||
}
|
||||
this.blockList = (List<Map<String, Integer>>) blockList;
|
||||
blockList.forEach(object -> {
|
||||
if (!(object instanceof Map)) return;
|
||||
Map<String, ?> map = (Map<String, ?>) object;
|
||||
locations.add(new Point((int) map.get("x"), (int) map.get("y"), (int) map.get("z")));
|
||||
});
|
||||
// generate();
|
||||
}
|
||||
|
||||
public void click(Player player, SteamwarUser user, int day, Location location) {
|
||||
if (day != this.day) return;
|
||||
if (!locations.contains(Point.toPoint(location))) return;
|
||||
if (NodeMember.getNodeMember(schematicId, user.getId()) != null) return;
|
||||
NodeMember.createNodeMember(schematicId, user.getId());
|
||||
LobbySystem.getMessage().send("ADVENT_CALENDAR_OPEN", player, SchematicNode.getSchematicNode(schematicId).getName());
|
||||
player.playSound(location, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
|
||||
}
|
||||
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
BlockData blockData = loc.getBlock().getBlockData();
|
||||
player.sendBlockChange(loc, blockData);
|
||||
});
|
||||
}
|
||||
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
player.sendBlockChange(loc, BEDROCK);
|
||||
});
|
||||
}
|
||||
|
||||
public void edit(Player player, Location location) {
|
||||
if (!players.contains(player)) return;
|
||||
Point point = Point.toPoint(location);
|
||||
if (locations.contains(point)) {
|
||||
locations.remove(point);
|
||||
} else {
|
||||
locations.add(point);
|
||||
}
|
||||
generate();
|
||||
Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> {
|
||||
BlockData blockData = location.getBlock().getBlockData();
|
||||
players.forEach(pl -> {
|
||||
if (pl == player) return;
|
||||
if (locations.contains(point)) {
|
||||
pl.sendBlockChange(location, blockData);
|
||||
} else {
|
||||
pl.sendBlockChange(location, BEDROCK);
|
||||
}
|
||||
});
|
||||
player.sendBlockChange(location, blockData);
|
||||
locations.forEach(p -> {
|
||||
Location loc = new Location(WORLD, p.x, p.y, p.z);
|
||||
player.sendBlockChange(loc, BEDROCK);
|
||||
});
|
||||
}, 4);
|
||||
}
|
||||
|
||||
private static final BlockData BEDROCK = Material.BEDROCK.createBlockData();
|
||||
|
||||
private void generate() {
|
||||
blockList.clear();
|
||||
locations.forEach(point -> {
|
||||
Map<String, Integer> pos = new HashMap<>();
|
||||
pos.put("x", point.x);
|
||||
pos.put("y", point.y);
|
||||
pos.put("z", point.z);
|
||||
blockList.add(pos);
|
||||
});
|
||||
AdventsCalendar.save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.lobby.special.advent;
|
||||
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.listener.BasicListener;
|
||||
import de.steamwar.sql.NodeMember;
|
||||
import de.steamwar.sql.SteamwarUser;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class PresentClickListener extends BasicListener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
if (present.getDay() != day) return;
|
||||
if (NodeMember.getNodeMember(present.getSchematicId(), SteamwarUser.get(event.getPlayer().getUniqueId()).getId()) != null) return;
|
||||
LobbySystem.getMessage().send("ADVENT_CALENDAR_MESSAGE", event.getPlayer());
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
|
||||
LocalDate localDate = LocalDate.now();
|
||||
int day = localDate.getDayOfMonth();
|
||||
|
||||
if (!AdventsCalendar.active()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.click(event.getPlayer(), SteamwarUser.get(event.getPlayer().getUniqueId()), day, block.getLocation());
|
||||
});
|
||||
}
|
||||
|
||||
// @EventHandler
|
||||
public void onPresentSetup(PlayerInteractEvent event) {
|
||||
Block block = event.getClickedBlock();
|
||||
if (block == null) return;
|
||||
AdventsCalendar.getPresentList().forEach(present -> {
|
||||
present.edit(event.getPlayer(), block.getLocation());
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user