Commit b12d64d2 authored by Sommer Patrick's avatar Sommer Patrick
Browse files

Updated Project with changes that where made at home

parent ea944bfe
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
package at.htltraun.dragonroyale;
import at.htltraun.dragonroyale.mysql.DBStatsAccount;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
public class BRPlayer {
private static Map<Player, BRPlayer> players = new HashMap<>();
private Player player;
private DBStatsAccount statsAccount;
private PlayerGameState playerGameState;
// ToDo: Add Mores wenn gebraucht
private BRPlayer(Player player) {
this.player = player;
players.put(player, this);
load();
}
public static BRPlayer getPlayerInstance(Player player) {
return players.containsKey(player) ? players.get(player) : new BRPlayer(player);
}
public static boolean removePlayer(Player player) { // On Player Leave
if (players.containsKey(player)) {
players.remove(player);
return true;
}
return false;
}
// --- setter & getter ---
public void load() {
statsAccount = new DBStatsAccount(MCBattleRoyale.getInstance().dbContext, player.getUniqueId());
playerGameState = PlayerGameState.LOBBY; // Players join on the lobby
}
public Player getPlayer() {
return player;
}
public DBStatsAccount getStatsAccount() {
return statsAccount;
}
public PlayerGameState getPlayerGameState() {
return playerGameState;
}
}
package at.htltraun.dragonroyale;
import at.htltraun.dragonroyale.brstuff.BRGameMap;
import at.htltraun.dragonroyale.commands.SetLobby;
import at.htltraun.dragonroyale.commands.SetGameMap;
import at.htltraun.dragonroyale.io.OwnConfiguration;
import at.htltraun.dragonroyale.io.StandardConfiguration;
import at.htltraun.dragonroyale.listener.JoinListener;
import at.htltraun.dragonroyale.listener.QuitListener;
import at.htltraun.dragonroyale.listener.WandListener;
import at.htltraun.dragonroyale.mysql.DBContext;
import at.htltraun.dragonroyale.mysql.DBStatsAccount;
import at.htltraun.dragonroyale.utils.Debug;
import at.htltraun.dragonroyale.utils.LobbyTimer;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class DragonRoyale extends JavaPlugin {
private static DragonRoyale instance;
protected DBContext dbContext;
public static StandardConfiguration configuration;
public static OwnConfiguration mapConfiguration;
private LobbyTimer lobbyTimer;
private ServerGameStates serverGameStates;
private BRGameMap brGameMap;
public static DragonRoyale getInstance() {
return instance;
}
@Override
public void onLoad() {
instance = this;
}
@Override
public void onEnable() {
initializeStandartConfig();
configuration = new StandardConfiguration();
if (configuration.isMysql_enabled()) connectToDatabase();
registerEvents();
registerCommands();
lobbyTimer = new LobbyTimer();
serverGameStates = ServerGameStates.LOBBY;
Debug.print("Set ServerGameState to LOBBY");
mapConfiguration = new OwnConfiguration("maps.yml");
}
@Override
public void onDisable() {
}
/**
* Loading standart config
*/
private void initializeStandartConfig() {
File f = new File(getDataFolder()+ File.separator+ "config.yml");
if(!f.exists())
{
this.saveDefaultConfig();
}
this.reloadConfig();
}
private void registerEvents() {
Bukkit.getPluginManager().registerEvents(new JoinListener(), this);
Debug.print("Registered JoinListener");
Bukkit.getPluginManager().registerEvents(new QuitListener(), this);
Debug.print("Registered QuitListener");
Bukkit.getPluginManager().registerEvents(new WandListener(), this);
Debug.print("Registered WandListener");
}
private void registerCommands() {
getCommand("setlobby").setExecutor(new SetLobby());
Debug.print("Registered setLobby command");
getCommand("setgamemap").setExecutor(new SetGameMap());
Debug.print("Registered setMap command");
}
private void connectToDatabase() {
dbContext = new DBContext(configuration.getMysql_host(), configuration.getMysql_port(), configuration.getMysql_user(), configuration.getMysql_pass(), configuration.getMysql_database());
DBStatsAccount.createTableIfNotExists(dbContext);
}
public LobbyTimer getLobbyTimer() {
return lobbyTimer;
}
public ServerGameStates getServerGameStates() {
return serverGameStates;
}
public void setServerGameStates(ServerGameStates serverGameStates) {
this.serverGameStates = serverGameStates;
}
public BRGameMap getBrGameMap() {
return brGameMap;
}
}
package at.htltraun.dragonroyale;
import me.clip.placeholderapi.external.EZPlaceholderHook;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class Placeholders extends EZPlaceholderHook {
public Placeholders(Plugin plugin) {
super(plugin, "mcbr");
}
@Override
public String onPlaceholderRequest(Player player, String s) {
if (s.equals("gamemap")) {
return player.getWorld().getName();
}
if (player == null) return "";
return null;
}
}
package at.htltraun.dragonroyale;
public enum PlayerGameState {
LOBBY, PLANE, FLYING, PARACHUTE, INGAME, DEAD;
}
package at.htltraun.dragonroyale;
public enum ServerGameStates {
LOBBY, PLANE, INGAME, END;
}
package at.htltraun.dragonroyale.brplane;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class BRPlane {
private World world;
private Location srcLoc;
private Location dstLoc;
private Vector path;
private Entity dragon;
public BRPlane(World world, Location srcLoc, Location dstLoc) {
this.world = world;
this.srcLoc = srcLoc;
this.dstLoc = dstLoc;
path = new Vector(dstLoc.getX(), dstLoc.getY(), world.getMaxHeight());
spawnPlane();
}
private void spawnPlane() {
dragon = world.spawnEntity(srcLoc, EntityType.ENDER_DRAGON);
}
public void addPassenger(Player player) {
dragon.setPassenger(player);
}
}
package at.htltraun.dragonroyale.brstuff;
import java.util.Random;
public class BRFlightPath {
private BRPoint p1;
private BRPoint p2;
public BRFlightPath(BRPoint p1, BRPoint p2) {
this.p1 = p1;
this.p2 = p2;
}
public static BRFlightPath randomFlightPath(BRPoint pos1, BRPoint pos2) { //ToDo: Algorithm
Random random = new Random();
BRPoint p1, p2;
double p1Dist = pos1.getX()+random.nextInt((int)(pos2.getX()-pos1.getX()));
double p2Dist = 0d;
if (pos2.getX()-p1Dist <= pos1.getX()-(pos2.getX()-pos1.getX())*0.2) {
p2Dist = pos2.getX()-random.nextInt((int)((pos2.getX()-pos1.getX())*0.08));
}
return new BRFlightPath(new BRPoint(p1Dist, pos1.getY()), new BRPoint(p2Dist, pos2.getY()));
}
public BRPoint getP1() {
return p1;
}
public BRPoint getP2() {
return p2;
}
}
package at.htltraun.dragonroyale.brstuff;
import at.htltraun.dragonroyale.DragonRoyale;
import at.htltraun.dragonroyale.brplane.BRPlane;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class BRGameMap {
private World world;
private String displayName;
BRPlane brPlane;
public BRGameMap(World world) {
this.world = world;
initialize();
}
private void initialize() {
displayName = DragonRoyale.mapConfiguration.getConfigConfiguration().getString("Maps."+world.getName()+".name");
BRPoint pos1 = new BRPoint();
BRPoint pos2 = new BRPoint();
pos1.setX(DragonRoyale.mapConfiguration.getConfigConfiguration().getDouble("Maps."+world.getName()+".pos1.x"));
pos1.setY(DragonRoyale.mapConfiguration.getConfigConfiguration().getDouble("Maps."+world.getName()+".pos1.z"));
pos2.setX(DragonRoyale.mapConfiguration.getConfigConfiguration().getDouble("Maps."+world.getName()+".pos2.x"));
pos2.setY(DragonRoyale.mapConfiguration.getConfigConfiguration().getDouble("Maps."+world.getName()+".pos2.z"));
BRFlightPath brFlightPath = BRFlightPath.randomFlightPath(pos1, pos2);
Location srcLoc = new Location(world, brFlightPath.getP1().getX(), world.getMaxHeight(), brFlightPath.getP1().getY());
Location dstLoc = new Location(world, brFlightPath.getP2().getX(), world.getMaxHeight(), brFlightPath.getP2().getY());
brPlane = new BRPlane(world, srcLoc, dstLoc);
}
public static BRGameMap randomGameMap() {
ArrayList<Object> maps = new ArrayList<>(Arrays.asList(DragonRoyale.mapConfiguration.getConfigConfiguration().getConfigurationSection("Maps").getKeys(false).toArray()));
Collections.shuffle(maps);
return new BRGameMap(Bukkit.getWorld((String)maps.get(0)));
}
public World getWorld() {
return world;
}
public String getDisplayName() {
return displayName;
}
public BRPlane getBrPlane() {
return brPlane;
}
}
package at.htltraun.dragonroyale.brstuff;
import org.bukkit.Location;
public class BRPoint {
private double x;
private double y;
public BRPoint(double x, double y) {
this.x = x;
this.y = y;
}
public BRPoint(){
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
}
package at.htltraun.dragonroyale.commands;
import at.htltraun.dragonroyale.DragonRoyale;
import at.htltraun.dragonroyale.utils.ChatAPI;
import at.htltraun.dragonroyale.utils.Permissions;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SetGameMap implements CommandExecutor {
private static Map<Player, World> setupMap = new HashMap<>();
public static Map<Player, World> getSetupMap() {
return setupMap;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
// -> setmap <name>
if (cmd.getName().equalsIgnoreCase("setgamemap")) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only supported ingame!");
return true;
}
if (args.length != 1) {
// ToDo: Help page
// ToDo: Permissions
return false;
}
Player player = (Player) sender;
if (!player.hasPermission(Permissions.SET_GAME_MAP.getPerm())) {
ChatAPI.sendNoPermissionMessage(player);
return true;
}
if (setupMap.containsKey(player)) return true;
setupMap.put(player, player.getWorld());
String world = player.getWorld().getName();
String name = ChatAPI.translateColor(args[0]);
DragonRoyale.mapConfiguration.getConfigConfiguration().set("Maps."+world+".name", name);
try {
DragonRoyale.mapConfiguration.getConfigConfiguration().save(DragonRoyale.mapConfiguration.getConfig());
String s = DragonRoyale.configuration.getSetGameMapMsg().replaceAll("%gamemap%", name);
ChatAPI.sendMessage(player, s);
} catch (IOException e) {
e.printStackTrace();
}
List<String> worldLore = new ArrayList<>();
worldLore.add(player.getWorld().getName());
ItemStack pos1 = new ItemStack(Material.STICK, 1);
ItemMeta meta = pos1.getItemMeta();
meta.setDisplayName("POS 1 (X)");
meta.setLore(worldLore);
pos1.setItemMeta(meta);
ItemStack pos2 = new ItemStack(Material.STICK, 1);
meta = pos1.getItemMeta();
meta.setDisplayName("POS 2 (Z)");
meta.setLore(worldLore);
pos2.setItemMeta(meta);
ItemStack pos3 = new ItemStack(Material.STICK, 1);
meta = pos1.getItemMeta();
meta.setDisplayName("POS 3 (Y)");
meta.setLore(worldLore);
pos3.setItemMeta(meta);
player.getInventory().clear();
player.getInventory().setItem(0, pos1);
player.getInventory().setItem(1, pos2);
player.getInventory().setItem(2, pos3);