file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
V3ClipSmoother.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3ClipSmoother.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import org.bukkit.Location; /** * @author Mato Kormuth * */ public class V3ClipSmoother { public static void smoothCompiledClip(final String path, final int a) throws Exception { V3CameraClip clip = V3CompiledReader.loadFile(path); clip = V3ClipSmoother.smooth(clip, a); V3CompiledWriter writer = V3CompiledWriter.createFile(path); writer.writeClip(clip); writer.close(); } public static V3CameraClip smoothClip(final V3CameraClip clip, final int a) { return V3ClipSmoother.smooth(clip, a); } /** * @param clip * @param i * @return */ private static V3CameraClip smooth(final V3CameraClip clip, final int a) { V3CameraClip newClip = new V3CameraClip(); for (int i = 0; i < clip.frames.size(); i++) { V3CameraFrame currentFrame = clip.frames.get(i); V3CameraFrame nextFrame = clip.frames.get(i + 1); newClip.addFrame(currentFrame); // Smooth movement (X,Y,Z) double x = 0; double y = 0; double z = 0; // Smooth rotation (Pitch, Yaw) float newYaw = (currentFrame.getCameraLocation().getYaw() + nextFrame.getCameraLocation().getYaw()) / 2; float newPitch = (currentFrame.getCameraLocation().getPitch() + nextFrame.getCameraLocation().getPitch()) / 2; Location newLoc = new Location(null, x, y, z, newYaw, newPitch); V3CameraFrame newFrame = new V3CameraFrame(newLoc, false); // Add new frame. newClip.addFrame(newFrame); } return newClip; } }
2,642
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3BasicRecorder.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3BasicRecorder.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import org.bukkit.ChatColor; import org.bukkit.entity.Player; /** * Nahravac tretej verzie. * * @author Mato Kormuth * */ public class V3BasicRecorder extends BasicRecorder { private Player player; private boolean recording; private V3CameraClip clip; private long frames = 0; private int ID = 0; /** * Pocet FPS v tomto nahravaci. */ public int FPS = 20; public V3BasicRecorder(final Player p, final int fps) { super(p, fps); } /** * Nastavi ID nahravaca. * * @param id * id */ @Override public void setID(final int id) { this.ID = id; } /** * Zacne nahravat. */ @Override public void record() { this.player.sendMessage("Recording " + ChatColor.RED + "[ID " + this.ID + "] " + ChatColor.YELLOW + " (" + this.FPS + "fps) " + ChatColor.GREEN + " has started..."); if (this.FPS > 20) this.player.sendMessage(ChatColor.RED + "Nahravanie na VIAC AKO 20 FPS nema vyznam! Vysledny zaznam bude rovnaky pri pouziti 20 aj 60 fps."); this.recording = true; //Start recording thread. new Thread(new Runnable() { @Override public void run() { V3BasicRecorder.this._record(); } }).start(); } /** * Zastavi nahravanie. */ @Override public void stop() { this.player.sendMessage("Stopped! Recorded " + this.frames + " frames (" + (this.frames / this.FPS) + " seconds)..."); this.recording = false; this.clip.save("advrecording" + System.currentTimeMillis()); this.player.sendMessage("Saved as: advrecording" + System.currentTimeMillis() + ".dat"); this.clip = null; } /** * Interna metoda urcena na nahravanie. */ private void _record() { while (this.recording) { if ((this.frames % 100) == 0) { if (this.FPS > 20) this.player.sendMessage(ChatColor.RED + "Nahravanie na VIAC AKO 20 FPS nema vyznam! Vysledny zaznam bude rovnaky pri pouziti 20 aj 60 fps."); this.player.sendMessage("Recorded " + this.frames + " frames (" + (this.frames / this.FPS) + " seconds)"); } //Pridaj frame. this.clip.addFrame(new V3CameraFrame(this.player.getLocation(), false)); this.frames++; if (this.frames > 30000) { //prekrocene maximum this.player.sendMessage("Zastavujem nahravanie. Prekrocene maximum frameov."); this.stop(); } try { Thread.sleep(1000 / this.FPS); } catch (InterruptedException e) { e.printStackTrace(); } } } /** * Vrati player. * * @return player */ @Override public Player getPlayer() { return this.player; } /** * Nastavi hraca. * * @param player * hrac */ @Override public void setPlayer(final Player player) { this.player = player; } }
4,315
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3CameraClip.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3CameraClip.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.bukkit.entity.Entity; import eu.matejkormuth.pexel.PexelCore.core.Paths; /** * Zlozity klip 3 urovne. * * @author Mato Kormuth * */ public class V3CameraClip { List<V3CameraFrame> frames = Collections.synchronizedList(new ArrayList<V3CameraFrame>()); List<Entity> entites = Collections.synchronizedList(new ArrayList<Entity>()); /** * Pocet ramov za sekundu v tomto klipe. */ public int FPS = 20; public int verzia = 3; public int metaCount = 0; /** * Prida jeden frame do zoznamu frameov. * * @param frame */ public void addFrame(final V3CameraFrame frame) { frame.clip = this; this.frames.add(frame); this.metaCount += frame.getMetaCount(); } /** * Prida kolekciu frameov do zoznamu frameov. * * @param frames */ public void addFrames(final List<V3CameraFrame> frames) { this.frames.addAll(frames); } /** * Vrati vsetky framy v klipe. * * @return */ public List<V3CameraFrame> getFrames() { return this.frames; } /** * Vrati frame specifikovany indexom. * * @param index * @return */ public V3CameraFrame getFrame(final int index) { return this.frames.get(index); } /** * Ulozi klip do suboru. * * @param meno * suboru. */ public void save(final String name) { PrintWriter writer = null; try { writer = new PrintWriter(new File(Paths.clips() + name + ".dat")); writer.println("#mertex-fun | CameraClip | v 1.2.1"); writer.println("#{fsavetime=" + System.currentTimeMillis() + ",fcount=" + this.frames.size() + ",ver=1}"); writer.println("#{FPS=" + this.FPS + "}"); writer.println("#{VERSION3}"); for (V3CameraFrame cframe : this.frames) { writer.println(cframe.serialize()); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } /** * Nacita klip zo suboru. * * @param meno * suboru * @return klip. */ public static V3CameraClip load(final String name) { System.out.println("Nacitavam subor " + name); V3CameraClip clip = new V3CameraClip(); clip.verzia = 3; BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(Paths.clips() + name + ".dat")); String line; while ((line = reader.readLine()) != null) { // Poznamky sa nesnaz nacitat ako bloky. if (!line.startsWith("#")) { // Pridaj blok. try { clip.addFrame(new V3CameraFrame(line)); } catch (Exception e) { e.printStackTrace(); } } else { // Poznamka alebo specialne metadata? if (line.startsWith("#{")) { if (line.startsWith("#{FPS=")) { clip.FPS = Integer.parseInt(line.substring(6, line.indexOf("}"))); } if (line.startsWith("#{VERSION3")) { clip.verzia = 3; } // Metadata! // Fajn, aj tak ich zatial nevyuzivame... } } } reader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("Nacitanych " + clip.getFrames().size() + " frameov."); return clip; } /** * Vrati pocet ramov v klipe. * * @return */ public int getNumOfFrames() { return this.frames.size(); } }
5,521
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3CameraFrame.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3CameraFrame.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.util.ArrayList; import java.util.List; import org.bukkit.Location; import org.bukkit.entity.Entity; /** * Reprezentuje ram/frame v klipe tretej verzie. * * @author Mato Kormuth * */ public class V3CameraFrame { /** * Pozicia hraca. */ private Location cameraLocation; /** * Specifikuje, ci frame obsahuje iba meta. */ private boolean isMetaOnly = false; /** * Zoznam dalsich extra dat v ramci. */ private List<V3Meta> metas = new ArrayList<V3Meta>(); /** * Zoom. */ private float zoom; /** * Odkaz na klip, ktoremu ram parti. */ public V3CameraClip clip; /** * Vytvori novy frame. * * @param cameraLocation * @param isMetaOnly */ public V3CameraFrame(final Location cameraLocation, final boolean isMetaOnly) { this.cameraLocation = cameraLocation; this.camX = cameraLocation.getX(); this.camY = cameraLocation.getY(); this.camZ = cameraLocation.getZ(); this.yaw = cameraLocation.getYaw(); this.pitch = cameraLocation.getPitch(); this.isMetaOnly = isMetaOnly; } public V3CameraFrame(final double x, final double y, final double z, final float yaw, final float pitch, final boolean isMetaOnly) { this.camX = x; this.camY = y; this.camZ = z; this.pitch = pitch; this.yaw = yaw; this.isMetaOnly = isMetaOnly; } public V3CameraFrame(final String line) { } public int verzia = 3; public double camX; public double camY; public double camZ; public float yaw; public float pitch; public String serialize() { // TODO Auto-generated method stub return null; } /** * Prida zaznam o pozicii entity. * * @param e */ public void addEntityLocation(final Entity e) { if (this.clip.entites.contains(e)) { // this.clip.entites. } } /** * @return the playerLocation */ public Location getCameraLocation() { return this.cameraLocation; } /** * @param playerLocation * the playerLocation to set */ public void setCameraLocation(final Location playerLocation) { this.cameraLocation = playerLocation; } /** * @return the isMeta */ public boolean isMetaOnly() { return this.isMetaOnly; } /** * @param isMetaOnly * the isMeta to set */ public void setMetaOnly(final boolean isMetaOnly) { this.isMetaOnly = isMetaOnly; } /** * @return the extraData */ public List<V3Meta> getMetas() { return this.metas; } /** * Prida extra data. * * @param data */ public void addMeta(final V3Meta data) { this.metas.add(data); } /** * @param metas * the extraData to set */ public void setMeta(final List<V3Meta> metas) { this.metas = metas; } /** * @return the zoom */ public float getZoom() { return this.zoom; } /** * @param zoom * the zoom to set */ public V3CameraFrame setZoom(final float zoom) { this.zoom = zoom; return this; // For method chaining. } /** * Vrati ci tento frame ma nejake meta. * * @return */ public boolean hasMeta() { return (this.metas.size() != 0); } public int getMetaCount() { return this.metas.size(); } }
4,596
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3Meta.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3Meta.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.io.DataOutputStream; import java.io.IOException; /** * Interface specifikujuci, ze dana trieda je V3Meta. * * @author Mato Kormuth * */ public interface V3Meta { /** * Typ meta. */ public V3MetaType getMetaType(); /** * Zapise meta do streamu. * * @param stream */ public void writeMeta(DataOutputStream stream) throws IOException; /** * Vrati ciselny typ META. * * @return */ public int getType(); }
1,385
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3Compiler.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3Compiler.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.io.IOException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * @author Mato Kormuth * */ public class V3Compiler implements Listener { private final V3CompiledWriter writer; // private String outPath; /** * Skompiluje V3 klip do kompilovanej formy za pomoci hraca. * * @param outPath * @param clip */ public V3Compiler(final String outPath) { // Priprav writer. this.writer = V3CompiledWriter.createFile(outPath); // this.outPath = outPath; // Priprav handlovanie eventov. Bukkit.getPluginManager().registerEvents(this, Pexel.getCore()); } /** * Skompiluje neskompilovany klip. * * @param clip * nezostaveny klip. * @param camera * hrac, ktory bude pouzity na zostavovanie. */ public void scheduleCompilation(final V3CameraClip clip, final Player camera) { // Vypisat varovanie. this.broadcast("Bola naplanovana kompilacia na hraca " + camera.getName()); // this.broadcast("Vystup: " + this.outPath); this.broadcast(ChatColor.YELLOW + "Kompilacia zacina za 15 sekund..."); this.notifyBySound(); V3Compiler.this.broadcast(ChatColor.GREEN + "Kompilacia zacina za 0 sekund..."); V3Compiler.this.compile(); } /** * */ private void notifyBySound() { // Upozorni vsetkych hracov na kompilaciu. for (Player p : Bukkit.getOnlinePlayers()) { p.playSound(p.getLocation(), Sound.NOTE_BASS, Float.MAX_VALUE, 0); p.playSound(p.getLocation(), Sound.NOTE_PIANO, Float.MAX_VALUE, 0); p.playSound(p.getLocation(), Sound.NOTE_PIANO, Float.MAX_VALUE, 1); p.playSound(p.getLocation(), Sound.NOTE_PIANO, Float.MAX_VALUE, 2); } } private void soundError() { } /** * Zacne zostavovanie cinematicu. */ protected void compile() { // Zaciatok. this.error("Tato operacia (compile) nie je podporovana!"); // Na konci unloadni dolezite veci, uloz subor a zrus eventy. this.finishCompiling(); } /** * Volane na konci kompilacie. */ private void finishCompiling() { this.broadcast(ChatColor.GREEN + "Kompilacia dokoncena! Upratujem bordel..."); // Odregistruj eventy. this.unregisterEvents(); // Zatvor subor. try { this.writer.close(); } catch (IOException e) { this.error(e.getMessage()); e.printStackTrace(); } } /** * Vypise do chatu spravu. * * @param message */ private void broadcast(final String message) { Bukkit.broadcastMessage(ChatColor.BLUE + "[V3cam] " + ChatColor.WHITE + message); } /** * Vypise do chatu chybu. * * @param message */ private void error(final String message) { this.soundError(); Bukkit.broadcastMessage(ChatColor.BLUE + "[V3cam] " + ChatColor.RED + message); } /** * Odregistruje udalosti. */ private void unregisterEvents() { // Treba unregistrovat eventy, inak sa server zblazni. } }
4,311
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaType.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3MetaType.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; /** * V3 Meta typ. * * @author Mato Kormuth * */ public enum V3MetaType { V3MetaEntityDamage, V3MetaEntityInventory, V3MetaEntityRemove, V3MetaEntitySpawn, V3MetaEntityTeleport, V3MetaEntityVelocity, V3MetaFallingSand, V3MetaParticleEffect, V3MetaSoundEffect, V3MetaExplosion, V3MetaEntityMove; }
1,226
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BasicRecorder.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/BasicRecorder.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import org.bukkit.ChatColor; import org.bukkit.entity.Player; /** * Reprezentuje zakladny nahravac * * @author Mato Kormuth * */ public class BasicRecorder { private Player player; private boolean recording; private long frames = 0; private int ID = 0; /** * Pocet FPS v tomto nahravaci. */ public int FPS = 20; /** * Vytvori instanciu nahravaca. * * @param p * hrac, podla ktoreho nahrava * @param fps * pocet obrazkov za sekundu */ public BasicRecorder(final Player p, final int fps) { this.player = p; this.FPS = fps; } /** * Nastavi ID nahravaca. * * @param id * id */ public void setID(final int id) { this.ID = id; } /** * Zacne nahravat. */ public void record() { this.player.sendMessage("Recording " + ChatColor.RED + "[ID " + this.ID + "] " + ChatColor.YELLOW + " (" + this.FPS + "fps) " + ChatColor.GREEN + " has started..."); if (this.FPS > 20) this.player.sendMessage(ChatColor.RED + "Nahravanie na VIAC AKO 20 FPS nema vyznam! Vysledny zaznam bude rovnaky pri pouziti 20 aj 60 fps."); this.recording = true; //Start recording thread. new Thread(new Runnable() { @Override public void run() { BasicRecorder.this._record(); } }).start(); } /** * Zastavi nahravanie. */ public void stop() { this.player.sendMessage("Stopped! Recorded " + this.frames + " frames (" + (this.frames / this.FPS) + " seconds)..."); this.recording = false; this.player.sendMessage("Saved as: recording" + System.currentTimeMillis() + ".dat"); } /** * Interna metoda urcena na nahravanie. */ private void _record() { while (this.recording) { if ((this.frames % 100) == 0) { if (this.FPS > 20) this.player.sendMessage(ChatColor.RED + "Nahravanie na VIAC AKO 20 FPS nema vyznam! Vysledny zaznam bude rovnaky pri pouziti 20 aj 60 fps."); this.player.sendMessage("Recorded " + this.frames + " frames (" + (this.frames / this.FPS) + " seconds)"); } this.frames++; if (this.frames > 30000) { //prekrocene maximum this.player.sendMessage("Zastavujem nahravanie. Prekrocene maximum frameov."); this.stop(); } try { Thread.sleep(1000 / this.FPS); } catch (InterruptedException e) { e.printStackTrace(); } } } /** * Vrati player. * * @return player */ public Player getPlayer() { return this.player; } /** * Nastavi hraca. * * @param player * hrac */ public void setPlayer(final Player player) { this.player = player; } }
4,154
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3Player.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3Player.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Queue; import java.util.concurrent.LinkedTransferQueue; import net.minecraft.server.v1_8_R1.EntityPlayer; import net.minecraft.server.v1_8_R1.PacketPlayOutPosition; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Entity; import org.bukkit.entity.FallingBlock; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityDamage; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityInventory; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityRemove; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntitySpawn; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityTeleport; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityVelocity; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaFallingSand; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaParticleEffect; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaSoundEffect; import eu.matejkormuth.pexel.PexelCore.util.PacketHelper; import eu.matejkormuth.pexel.PexelCore.util.SoundUtility; /** * Prehravac V3 klipov. * * @author Mato Kormuth * */ public class V3Player { private final Player player; private final V3CameraClip clip; private final Map<Long, LivingEntity> entityMapping = Collections.synchronizedMap(new HashMap<Long, LivingEntity>()); private boolean playing; private int currentFrameNum = 0; private V3CameraFrame currentFrame; private int syncUpdateTaskId; private final Queue<Runnable> syncTasks = new LinkedTransferQueue<Runnable>(); private int syncTaskCounter = 0; private Runnable onCompleted; // private double lastX; // private double lastY; // private double lastZ; // private int eid = 0; public V3Player(final Player camera, final V3CameraClip clip) { this.player = camera; this.clip = clip; } public void play() { this.playing = true; this.player.setAllowFlight(true); this.player.setFlying(true); this.player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0)); // Schedule sync updates. this.syncUpdateTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask( Pexel.getCore(), new Runnable() { @Override public void run() { V3Player.this.syncUpdate(); } }, 0, 1); new Thread(new Runnable() { @Override public void run() { V3Player.this.unsyncUpdate(); // Cancel sync updates. Bukkit.getScheduler().cancelTask(V3Player.this.syncUpdateTaskId); } }).start(); } /** * Volane 1000 / FPS krat za sekundu. */ @SuppressWarnings("deprecation") private void unsyncUpdate() { while (this.playing) { // Get next frame. V3CameraFrame frame; if ((frame = this.nextFrame()) != null) { // Nastav kameru. // Hracovi posli paketu o teleportacii. Server aktualizuje // hracovu polohu v synUpdate, aby sa necrashoval. PacketHelper.send(this.player, new PacketPlayOutPosition(frame.camX, frame.camY, frame.camZ, frame.yaw, frame.pitch, com.google.common.collect.Sets.newLinkedHashSet())); // Spracuj zoom. // Spracuj meta. for (V3Meta meta : frame.getMetas()) { switch (meta.getMetaType()) { case V3MetaEntityDamage: final V3MetaEntityDamage v3MetaEntityDamage = ((V3MetaEntityDamage) meta); //Bezpecne this.syncTasks.add(new Runnable() { @Override public void run() { V3Player.this.getEntity( v3MetaEntityDamage.getInternalId()).damage( v3MetaEntityDamage.getDamage()); } }); break; case V3MetaEntityInventory: final V3MetaEntityInventory v3MetaEntityInventory = (V3MetaEntityInventory) meta; //Bezpecne. this.syncTasks.add(new Runnable() { @Override public void run() { LivingEntity le = V3Player.this.getEntity(v3MetaEntityInventory.getInternalId()); switch (v3MetaEntityInventory.getSlot()) { case 0: le.getEquipment() .setBoots( new ItemStack( v3MetaEntityInventory.getItemType(), 1)); break; case 1: le.getEquipment() .setLeggings( new ItemStack( v3MetaEntityInventory.getItemType(), 1)); break; case 2: le.getEquipment() .setChestplate( new ItemStack( v3MetaEntityInventory.getItemType(), 1)); break; case 3: le.getEquipment() .setHelmet( new ItemStack( v3MetaEntityInventory.getItemType(), 1)); break; case 4: le.getEquipment() .setItemInHand( new ItemStack( v3MetaEntityInventory.getItemType(), 1)); break; } } }); break; case V3MetaEntityRemove: final V3MetaEntityRemove v3MetaEntityRemove = (V3MetaEntityRemove) meta; //Bezpecne. this.syncTasks.add(new Runnable() { @Override public void run() { V3Player.this.removeRemove(v3MetaEntityRemove.getInternalId()); } }); break; case V3MetaEntitySpawn: final V3MetaEntitySpawn v3MetaEntitySpawn = (V3MetaEntitySpawn) meta; //Pre bezpocnost mudi byt synchronne. this.syncTasks.add(new Runnable() { @Override public void run() { Entity e = V3Player.this.player.getWorld() .spawnEntity( new Location( V3Player.this.player.getWorld(), v3MetaEntitySpawn.getPosX(), v3MetaEntitySpawn.getPosY(), v3MetaEntitySpawn.getPosZ(), v3MetaEntitySpawn.getYaw(), v3MetaEntitySpawn.getPitch()), v3MetaEntitySpawn.getEntityType()); if (e instanceof LivingEntity) { V3Player.this.addEntity( v3MetaEntitySpawn.getInternalId(), (LivingEntity) e); //NMS.makeIdiot((LivingEntity) e); //Osproti entitu. } } }); break; case V3MetaEntityTeleport: final V3MetaEntityTeleport v3MetaEntityTeleport = (V3MetaEntityTeleport) meta; //Musi byt synchronne pre bezpecnost. this.syncTasks.add(new Runnable() { @Override public void run() { V3Player.this.getEntity( v3MetaEntityTeleport.getInternalId()) .teleport( new Location( V3Player.this.player.getWorld(), v3MetaEntityTeleport.getPosX(), v3MetaEntityTeleport.getPosY(), v3MetaEntityTeleport.getPosZ())); } }); break; case V3MetaEntityVelocity: final V3MetaEntityVelocity v3MetaEntityVelocity = (V3MetaEntityVelocity) meta; //Musi byt synchronne pre bezpocnost. this.syncTasks.add(new Runnable() { @Override public void run() { V3Player.this.getEntity( v3MetaEntityVelocity.getInternalId()) .setVelocity( new Vector( v3MetaEntityVelocity.getVelX(), v3MetaEntityVelocity.getVelY(), v3MetaEntityVelocity.getVelZ())); } }); ; break; case V3MetaFallingSand: final V3MetaFallingSand v3MetaFallingSand = (V3MetaFallingSand) meta; //Packet rewrite /* * [13:34:41] [Netty IO #5/DEBUG]: OUT: [PLAY:14] * net.minecraft.server.v1_7_R3.PacketPlayOutSpawnEntity[id=3804, type=70, x=9,50, y=64,50, * z=549,50] [13:34:41] [Netty IO #5/DEBUG]: OUT: [PLAY:28] * net.minecraft.server.v1_7_R3.PacketPlayOutEntityMetadata[] [13:34:41] [Netty IO * #5/DEBUG]: OUT: [PLAY:18] * net.minecraft.server.v1_7_R3.PacketPlayOutEntityVelocity[id=3804, x=0,00, y=0,00, z=0,00] * [13:34:41] [Netty IO #5/DEBUG]: OUT: [PLAY:25] * net.minecraft.server.v1_7_R3.PacketPlayOutEntityHeadRotation[id=3804, rot=0] */ /* * PacketHelper.send( this.player, ((PacketPlayOutSpawnEntity) new * V3PacketPlayOutSpawnEntity( Mertexfun.random.nextInt(), v3MetaFallingSand.getPosX(), * v3MetaFallingSand.getPosY(), v3MetaFallingSand.getPosZ(), 0, 0, 70, * v3MetaFallingSand.getMaterial().getId() | (0 << 0x10), v3MetaFallingSand.getVelX(), * v3MetaFallingSand.getVelY(), v3MetaFallingSand.getVelZ()))); */ //Musi byt pre bezpocnost synchronne. this.syncTasks.add(new Runnable() { @Override public void run() { FallingBlock fb = V3Player.this.player.getWorld() .spawnFallingBlock( new Location( V3Player.this.player.getWorld(), v3MetaFallingSand.getPosX(), v3MetaFallingSand.getPosY(), v3MetaFallingSand.getPosZ()), v3MetaFallingSand.getMaterial(), (byte) 0); fb.setVelocity(new Vector( v3MetaFallingSand.getVelX(), v3MetaFallingSand.getVelY(), v3MetaFallingSand.getVelZ())); fb.setDropItem(false); fb.setMetadata( "isV3", new FixedMetadataValue(Pexel.getCore(), true)); } }); break; case V3MetaParticleEffect: V3MetaParticleEffect v3MetaParticleEffect = (V3MetaParticleEffect) meta; /* * ParticleEffect2.fromId(v3MetaParticleEffect.getParticle()) .display( new * Location(this.player.getWorld(), v3MetaParticleEffect.getPosX(), * v3MetaParticleEffect.getPosY(), v3MetaParticleEffect.getPosZ()), * v3MetaParticleEffect.getOffsetX(), v3MetaParticleEffect.getOffsetY(), * v3MetaParticleEffect.getOffsetZ(), v3MetaParticleEffect.getSpeed(), * v3MetaParticleEffect.getAmount()); */ break; case V3MetaSoundEffect: V3MetaSoundEffect v3MetaSoundEffect = (V3MetaSoundEffect) meta; SoundUtility.playCustomSound(this.player, v3MetaSoundEffect.getName(), v3MetaSoundEffect.getVolume(), v3MetaSoundEffect.getPitch()); break; case V3MetaExplosion: break; case V3MetaEntityMove: //final V3MetaEntityMove v3MetaEntityMove = (V3MetaEntityMove) meta; //PacketHelper.send( // this.player, // new PacketPlayOutRelEntityMove( // V3Player.this.getEntity( /// v3MetaEntityMove.getInternalId()) // .getEntityId(), // NMS.fixedPointNumByte(v3MetaEntityMove.getMovX()), // NMS.fixedPointNumByte(v3MetaEntityMove.getMovY()), // NMS.fixedPointNumByte(v3MetaEntityMove.getMovZ()))); /* * NMS.relMoveEntity( V3Player.this.getEntity(v3MetaEntityMove.getInternalId()), * v3MetaEntityMove.getMovX(), v3MetaEntityMove.getMovY(), v3MetaEntityMove.getMovZ()); */ //Synchronizovane. this.syncTasks.add(new Runnable() { @Override public void run() { } }); break; default: break; } } } else { this.playing = false; // Remove things, clean up. synchronized (this.entityMapping) { // Kill all left entites. for (LivingEntity e : this.entityMapping.values()) { e.damage(400D); } } this.player.setFlying(false); if (this.player.getGameMode() == GameMode.SURVIVAL) this.player.setAllowFlight(false); this.player.removePotionEffect(PotionEffectType.INVISIBILITY); //Zavolaj to co treba. if (this.onCompleted != null) this.onCompleted.run(); } // Spinkaj. try { Thread.sleep(1000 / this.clip.FPS); } catch (InterruptedException e) { e.printStackTrace(); } } } /** * @param internalId */ private void removeRemove(final long internalId) { synchronized (this.entityMapping) { this.getEntity(internalId).damage(500D); this.entityMapping.remove(internalId); } } /** * @param internalId * @param e */ private void addEntity(final long internalId, final LivingEntity e) { synchronized (this.entityMapping) { this.entityMapping.put(internalId, e); } } /** * Vrati entitu podla internalID. * * @param internalId * @return */ private LivingEntity getEntity(final long internalId) { return this.entityMapping.get(internalId); } /** * Vrati dalsi frame. * * @return */ private V3CameraFrame nextFrame() { this.currentFrameNum++; if (this.currentFrameNum < this.clip.frames.size() + 1) { return (this.currentFrame = this.clip.frames.get(this.currentFrameNum - 1)); } else { return null; } } /** * Volane 20 krat za sekundu. */ public void syncUpdate() { if (this.playing) { //Pomalicky zachovovaj poziciu hraca aj na serveri. EntityPlayer ep = ((CraftPlayer) this.player).getHandle(); ep.locX = this.currentFrame.camX; ep.locY = this.currentFrame.camY; ep.locZ = this.currentFrame.camZ; //Spracuj ulohy, co sa musia spravit synchronizovane. this.syncTaskCounter = 0; while (this.syncTaskCounter < Short.MAX_VALUE && this.syncTasks.peek() != null) { this.syncTasks.poll().run(); this.syncTaskCounter++; } } } /** * @param runnable */ public void setOnCompleted(final Runnable runnable) { this.onCompleted = runnable; } }
23,214
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3CompiledReader.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/V3CompiledReader.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics; import java.io.DataInputStream; import java.io.EOFException; import java.io.FileInputStream; import java.io.IOException; import org.bukkit.Location; import org.bukkit.World; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityDamage; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityInventory; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityRemove; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntitySpawn; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityTeleport; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaEntityVelocity; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaFallingSand; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaParticleEffect; import eu.matejkormuth.pexel.PexelCore.cinematics.v3meta.V3MetaSoundEffect; /** * Nacitava skompilovane V3 klipy. * * @author Mato Kormuth * */ public class V3CompiledReader { /** * Stream pouzivany na nacitanie suboru. */ private final DataInputStream input; /** * Kuzelne cislo 1. */ public final static int MAGIC_1 = 86; /** * Kuzelne cislo 2. */ public final static int MAGIC_2 = 114; /** * Verzia suboru. */ public final static int VERSION = 1; /** * Klip. */ private V3CameraClip clip; /** * Svet. */ private World w; public static V3CameraClip loadFile(final String path) throws Exception { return new V3CompiledReader(path).clip; } private V3CompiledReader(final String path) throws Exception { this.input = new DataInputStream(new FileInputStream(path)); this.readFile(); } /** * Nacita data zo suboru do pamate. * * @throws Exception */ private void readFile() throws Exception { this.clip = new V3CameraClip(); this.readClip(); } /** * * @param clip * @throws Exception */ private void readClip() throws Exception { // read FileHeader. this.readFileHeader(); // read Frames. while (true) { try { V3CameraFrame frame = this.readFrameHeader(); this.clip.addFrame(frame); } catch (EOFException exc) { break; } } this.close(); } private void readFileHeader() throws Exception { // Check for magic. byte magic1 = this.input.readByte(); byte magic2 = this.input.readByte(); if (magic1 != V3CompiledReader.MAGIC_1 || magic2 != V3CompiledReader.MAGIC_2) throw new Exception("This is not a valid V3C file!"); this.input.readByte(); // Version byte this.clip.FPS = this.input.readByte(); } private V3CameraFrame readFrameHeader() throws IOException { // read FrameHeader. double x = this.input.readDouble(); double y = this.input.readDouble(); double z = this.input.readDouble(); float yaw = this.input.readFloat(); float pitch = this.input.readFloat(); float zoom = this.input.readFloat(); boolean isMetaOnly = this.input.readBoolean(); V3CameraFrame frame = new V3CameraFrame( new Location(this.w, x, y, z, yaw, pitch), isMetaOnly).setZoom(zoom); // Process meta. short metaCount = this.input.readShort(); // MetaCount for (short i = 0; i < metaCount; i++) { // Meta type byte metaType = this.input.readByte(); switch (metaType) { case 0: frame.addMeta(V3MetaSoundEffect.readMeta(this.input)); break; case 1: frame.addMeta(V3MetaEntitySpawn.readMeta(this.input)); break; case 2: frame.addMeta(V3MetaEntityDamage.readMeta(this.input)); break; case 3: frame.addMeta(V3MetaEntityTeleport.readMeta(this.input)); break; case 4: frame.addMeta(V3MetaEntityInventory.readMeta(this.input)); break; case 5: frame.addMeta(V3MetaEntityRemove.readMeta(this.input)); break; case 6: frame.addMeta(V3MetaEntityVelocity.readMeta(this.input)); break; case 7: frame.addMeta(V3MetaParticleEffect.readMeta(this.input)); break; case 8: frame.addMeta(V3MetaFallingSand.readMeta(this.input)); break; } } return frame; } /** * Zatvori subor. * * @throws IOException */ public void close() throws IOException { this.input.close(); } }
6,010
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityInventory.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityInventory.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityInventory implements V3Meta { private final long internalId; private final byte slot; private final int itemType; /** * @param internalId * @param slot * @param type */ public V3MetaEntityInventory(final long internalId, final byte slot, final int type) { super(); this.internalId = internalId; this.slot = slot; this.itemType = type; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeLong(this.internalId); stream.writeByte(this.slot); stream.writeInt(this.itemType); } public static V3MetaEntityInventory readMeta(final DataInputStream stream) throws IOException { long internalId = stream.readLong(); byte slot = stream.readByte(); int type = stream.readInt(); return new V3MetaEntityInventory(internalId, slot, type); } @Override public int getType() { return 4; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityInventory; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } /** * @return the slot */ public byte getSlot() { return this.slot; } /** * @return the itemType */ public int getItemType() { return this.itemType; } }
2,650
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaExplosion.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaExplosion.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaExplosion implements V3Meta { private double posX; private double posY; private double posZ; @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaExplosion; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { } @Override public int getType() { return 0; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } }
1,844
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityVelocity.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityVelocity.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityVelocity implements V3Meta { private final long internalId; private final double velX; private final double velY; private final double velZ; /** * @param internalId * @param velX * @param velY * @param velZ */ public V3MetaEntityVelocity(final long internalId, final double velX, final double velY, final double velZ) { super(); this.internalId = internalId; this.velX = velX; this.velY = velY; this.velZ = velZ; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeLong(this.internalId); stream.writeDouble(this.velX); stream.writeDouble(this.velY); stream.writeDouble(this.velZ); } public static V3MetaEntityVelocity readMeta(final DataInputStream stream) throws IOException { long internalId = stream.readLong(); double velX = stream.readDouble(); double velY = stream.readDouble(); double velZ = stream.readDouble(); return new V3MetaEntityVelocity(internalId, velX, velY, velZ); } @Override public int getType() { return 6; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityVelocity; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } /** * @return the velX */ public double getVelX() { return this.velX; } /** * @return the velY */ public double getVelY() { return this.velY; } /** * @return the velZ */ public double getVelZ() { return this.velZ; } }
2,959
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityTeleport.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityTeleport.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityTeleport implements V3Meta { private final double posX; private final double posY; private final double posZ; private final float yaw; private final float pitch; private final long internalId; /** * @param posX * @param posY * @param posZ * @param yaw * @param pitch * @param internalId */ public V3MetaEntityTeleport(final double posX, final double posY, final double posZ, final float yaw, final float pitch, final long internalId) { super(); this.posX = posX; this.posY = posY; this.posZ = posZ; this.yaw = yaw; this.pitch = pitch; this.internalId = internalId; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.posX); stream.writeDouble(this.posY); stream.writeDouble(this.posZ); stream.writeFloat(this.yaw); stream.writeFloat(this.pitch); stream.writeLong(this.internalId); } public static V3MetaEntityTeleport readMeta(final DataInputStream stream) throws IOException { double x = stream.readDouble(); double y = stream.readDouble(); double z = stream.readDouble(); float yaw = stream.readFloat(); float pitch = stream.readFloat(); long internalId = stream.readLong(); return new V3MetaEntityTeleport(x, y, z, yaw, pitch, internalId); } @Override public int getType() { return 3; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityTeleport; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } /** * @return the yaw */ public float getYaw() { return this.yaw; } /** * @return the pitch */ public float getPitch() { return this.pitch; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } }
3,511
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityRemove.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityRemove.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityRemove implements V3Meta { private final long internalId; /** * @param internalId2 */ public V3MetaEntityRemove(final long internalId2) { this.internalId = internalId2; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeLong(this.internalId); } public static V3MetaEntityRemove readMeta(final DataInputStream stream) throws IOException { long internalId = stream.readLong(); return new V3MetaEntityRemove(internalId); } @Override public int getType() { return 5; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityRemove; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } }
2,051
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaFallingSand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaFallingSand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import org.bukkit.Material; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaFallingSand implements V3Meta { private final double posX; private final double posY; private final double posZ; private final double velX; private final double velY; private final double velZ; private final Material material; /** * @param posX * @param posY * @param posZ * @param velX * @param velY * @param velZ * @param material */ public V3MetaFallingSand(final double posX, final double posY, final double posZ, final double velX, final double velY, final double velZ, final Material material) { this.posX = posX; this.posY = posY; this.posZ = posZ; this.velX = velX; this.velY = velY; this.velZ = velZ; this.material = material; } @SuppressWarnings("deprecation") @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.posX); stream.writeDouble(this.posY); stream.writeDouble(this.posZ); stream.writeDouble(this.velX); stream.writeDouble(this.velY); stream.writeDouble(this.velZ); stream.writeInt(this.material.getId()); } @SuppressWarnings("deprecation") public static V3MetaFallingSand readMeta(final DataInputStream stream) throws IOException { double posX = stream.readDouble(); double posY = stream.readDouble(); double posZ = stream.readDouble(); double velX = stream.readDouble(); double velY = stream.readDouble(); double velZ = stream.readDouble(); Material material = Material.getMaterial(stream.readInt()); return new V3MetaFallingSand(posX, posY, posZ, velX, velY, velZ, material); } @Override public int getType() { return 8; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaFallingSand; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } /** * @return the velX */ public double getVelX() { return this.velX; } /** * @return the velY */ public double getVelY() { return this.velY; } /** * @return the velZ */ public double getVelZ() { return this.velZ; } /** * @return the material */ public Material getMaterial() { return this.material; } }
3,944
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaSoundEffect.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaSoundEffect.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author M * */ public class V3MetaSoundEffect implements V3Meta { private static final int TYPEID = 0; private final double posX; private final double posY; private final double posZ; private final float pitch; private final float volume; private final String name; /** * Vytvori novy V3MetaSoundEffect so specifikovanymi udajmi. * * @param posX * @param posY * @param posZ * @param pitch * @param volume * @param name */ public V3MetaSoundEffect(final double posX, final double posY, final double posZ, final float pitch, final float volume, final String name) { this.posX = posX; this.posY = posY; this.posZ = posZ; this.pitch = pitch; this.volume = volume; this.name = name; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.posX); stream.writeDouble(this.posY); stream.writeDouble(this.posZ); stream.writeFloat(this.volume); stream.writeFloat(this.pitch); stream.writeUTF(this.name); } public static V3MetaSoundEffect readMeta(final DataInputStream stream) throws IOException { double x = stream.readDouble(); double y = stream.readDouble(); double z = stream.readDouble(); float volume = stream.readFloat(); float pitch = stream.readFloat(); String name = stream.readUTF(); return new V3MetaSoundEffect(x, y, z, pitch, volume, name); } @Override public int getType() { return V3MetaSoundEffect.TYPEID; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaSoundEffect; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } /** * @return the pitch */ public float getPitch() { return this.pitch; } /** * @return the volume */ public float getVolume() { return this.volume; } /** * @return the name */ public String getName() { return this.name; } }
3,605
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntitySpawn.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntitySpawn.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import org.bukkit.entity.EntityType; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * * @author Mato Kormuth * */ public class V3MetaEntitySpawn implements V3Meta { private static final int TYPEID = 1; private final double posX; private final double posY; private final double posZ; private final float yaw; private final float pitch; private final EntityType entityType; private final long internalId; /** * Vytvori novy V3MetaEntitySpawn so specifikovanymi udajmi. * * @param posX * @param posY * @param posZ * @param yaw * @param pitch * @param type * @param internalId */ public V3MetaEntitySpawn(final double posX, final double posY, final double posZ, final float yaw, final float pitch, final EntityType type, final long internalId) { this.posX = posX; this.posY = posY; this.posZ = posZ; this.yaw = yaw; this.pitch = pitch; this.entityType = type; this.internalId = internalId; } @SuppressWarnings("deprecation") @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.posX); stream.writeDouble(this.posY); stream.writeDouble(this.posZ); stream.writeFloat(this.yaw); stream.writeFloat(this.pitch); stream.writeInt(this.entityType.getTypeId()); stream.writeLong(this.internalId); } @SuppressWarnings("deprecation") public static V3MetaEntitySpawn readMeta(final DataInputStream stream) throws IOException { double x = stream.readDouble(); double y = stream.readDouble(); double z = stream.readDouble(); float yaw = stream.readFloat(); float pitch = stream.readFloat(); EntityType type = EntityType.fromId(stream.readInt()); long internalId = stream.readLong(); return new V3MetaEntitySpawn(x, y, z, yaw, pitch, type, internalId); } @Override public int getType() { return V3MetaEntitySpawn.TYPEID; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntitySpawn; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } /** * @return the yaw */ public float getYaw() { return this.yaw; } /** * @return the pitch */ public float getPitch() { return this.pitch; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } /** * @return the entityType */ public EntityType getEntityType() { return this.entityType; } }
4,140
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaParticleEffect.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaParticleEffect.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaParticleEffect implements V3Meta { private final double posX; private final double posY; private final double posZ; private final int particle; /** * @param posX * @param posY * @param posZ * @param particle */ public V3MetaParticleEffect(final double posX, final double posY, final double posZ, final int particle) { this.posX = posX; this.posY = posY; this.posZ = posZ; this.particle = particle; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.posX); stream.writeDouble(this.posY); stream.writeDouble(this.posZ); stream.writeInt(this.particle); } public static V3MetaParticleEffect readMeta(final DataInputStream stream) throws IOException { double x = stream.readDouble(); double y = stream.readDouble(); double z = stream.readDouble(); int particle = stream.readInt(); return new V3MetaParticleEffect(x, y, z, particle); } @Override public int getType() { return 7; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaParticleEffect; } /** * @return the posX */ public double getPosX() { return this.posX; } /** * @return the posY */ public double getPosY() { return this.posY; } /** * @return the posZ */ public double getPosZ() { return this.posZ; } /** * @return the particle */ public int getParticle() { return this.particle; } /** * @return */ public float getOffsetX() { // TODO Auto-generated method stub return 0; } /** * @return */ public float getOffsetY() { // TODO Auto-generated method stub return 0; } /** * @return */ public float getOffsetZ() { // TODO Auto-generated method stub return 0; } /** * @return */ public float getSpeed() { // TODO Auto-generated method stub return 1; } /** * @return */ public int getAmount() { // TODO Auto-generated method stub return 20; } }
3,568
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityDamage.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityDamage.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityDamage implements V3Meta { private static final int TYPEID = 2; private final long internalId; private final float damage; /** * @param internalId * @param damage */ public V3MetaEntityDamage(final long internalId, final float damage) { this.internalId = internalId; this.damage = damage; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeLong(this.internalId); stream.writeFloat(this.damage); } public static V3MetaEntityDamage readMeta(final DataInputStream stream) throws IOException { long internalId = stream.readLong(); float damage = stream.readFloat(); return new V3MetaEntityDamage(internalId, damage); } @Override public int getType() { return V3MetaEntityDamage.TYPEID; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityDamage; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } /** * @return the damage */ public float getDamage() { return this.damage; } }
2,429
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
V3MetaEntityMove.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/cinematics/v3meta/V3MetaEntityMove.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.cinematics.v3meta; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import eu.matejkormuth.pexel.PexelCore.cinematics.V3Meta; import eu.matejkormuth.pexel.PexelCore.cinematics.V3MetaType; /** * @author Mato Kormuth * */ public class V3MetaEntityMove implements V3Meta { private final double movX; private final double movY; private final double movZ; private final float yaw; private final float pitch; private final long internalId; /** * @param movX * @param movY * @param movZ * @param yaw * @param pitch * @param internalId */ public V3MetaEntityMove(final double movX, final double movY, final double movZ, final float yaw, final float pitch, final long internalId) { super(); this.movX = movX; this.movY = movY; this.movZ = movZ; this.yaw = yaw; this.pitch = pitch; this.internalId = internalId; } @Override public V3MetaType getMetaType() { return V3MetaType.V3MetaEntityMove; } @Override public void writeMeta(final DataOutputStream stream) throws IOException { stream.writeDouble(this.movX); stream.writeDouble(this.movY); stream.writeDouble(this.movZ); stream.writeFloat(this.yaw); stream.writeFloat(this.pitch); stream.writeLong(this.internalId); } public static V3MetaEntityMove readMeta(final DataInputStream stream) throws IOException { double x = stream.readDouble(); double y = stream.readDouble(); double z = stream.readDouble(); float yaw = stream.readFloat(); float pitch = stream.readFloat(); long internalId = stream.readLong(); return new V3MetaEntityMove(x, y, z, yaw, pitch, internalId); } @Override public int getType() { return 10; } /** * @return the movX */ public double getMovX() { return this.movX; } /** * @return the movY */ public double getMovY() { return this.movY; } /** * @return the movZ */ public double getMovZ() { return this.movZ; } /** * @return the yaw */ public float getYaw() { return this.yaw; } /** * @return the pitch */ public float getPitch() { return this.pitch; } /** * @return the internalId */ public long getInternalId() { return this.internalId; } }
3,492
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
LocationsType.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/LocationsType.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; import javax.xml.bind.annotation.XmlType; /** * Type of locations in {@link MapData}. */ @XmlType(name = "locationtype") public enum LocationsType { /** * Co-ordinates are in absolute values. */ ABSOLUTE, /** * Co-ordinates are in relative values. Absolute values are evaulated using {@link MapData#anchor}. */ RELATIVE; }
1,236
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ArenaOption.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/ArenaOption.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Specifies that this field represents arena option. Apply on fields in {@link AbstractArena} or {@link AdvancedArena} * to flag them as arena 'options'. * * @deprecated Replaced by {@link MapData}. Try to use {@link MapData} where possible. May be removed in future. */ @Target({ java.lang.annotation.ElementType.FIELD }) @Retention(RetentionPolicy.RUNTIME) @Deprecated public @interface ArenaOption { /** * Name of option. * * @return the name of option */ String name(); /** * Whether the option should be persistent (saved and loaded when arena is setting up). Default value is true. * * @return flag if the value should be persistent */ boolean persistent() default true; }
1,747
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
AdvancedArena.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/AdvancedArena.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; import java.util.ArrayList; import me.confuser.barapi.BarAPI; import org.apache.commons.lang.NullArgumentException; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.potion.PotionEffectType; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Log; import eu.matejkormuth.pexel.PexelCore.matchmaking.GameState; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; import eu.matejkormuth.pexel.PexelCore.util.NetworkCCFormatter; /** * Arena that has built-in support for pre-game lobby and stuff... Also implements {@link Listener} and calls * {@link org.bukkit.plugin.PluginManager#registerEvents(Listener, org.bukkit.plugin.Plugin)} in constructor. * * @author Mato Kormuth * */ public abstract class AdvancedArena extends AbstractArena implements Listener { /** * Amount of players, that is required to start the countdown. */ public int minimumPlayers = 0; /** * Lenght of countdown in seconds. */ public int countdownLenght = 10; /** * Location of this arena game spawn. */ public Location gameSpawn; /** * Specifies if the countdown should be canceled, if a player leaves arena and there is not enough players to start * game, but the countdown is alredy running. */ public boolean countdownCanCancel = true; /** * Specifies if players can respawn in this arena, or not (default true). */ public boolean respawnAllowed = true; /** * Spcifies if the boss bar should be used for displaying time to start. */ public boolean useBossBar = true; /** * Time left to game start. */ public int countdownTimeLeft = this.countdownLenght; /** * Specifies, if the arena should call <code>reset()</code> function automaticaly when game ends. */ public boolean autoReset = true; /** * Specifies, if inventory actions are enabled in this arena (default: true). */ public boolean inventoryDisabled = true; /** * Chat format for countdown message. */ public String countdownFormat = "%timeleft% seconds to game start!"; // Bukkit task id of countdown. protected int countdownTaskId = 0; /** * Identifies if the game has started. */ private boolean gameStarted = false; /** * @param minigame * @param arenaName * @param region * @param maxPlayers */ public AdvancedArena(final Minigame minigame, final String arenaName, final MapData mapData) { super(minigame, arenaName, mapData); this.minimumPlayers = mapData.getOption_Integer(MapData.KEY_MINIMAL_PLAYERS); this.countdownLenght = mapData.getOption_Integer(MapData.KEY_COUNTDOWN_LENGHT); this.gameSpawn = mapData.getLocation(MapData.KEY_ARENA_SPAWN); NetworkCCFormatter.sendConstructor(this); // TODO: Registers events in bukkit. Needs to be reworked. Bukkit.getPluginManager().registerEvents(this, Pexel.getCore()); } /** * Clear player's inventory including armor slots. * * @param player * player to clear inventory */ public void clearPlayerInventory(final Player player) { if (player == null) { throw new NullArgumentException("player"); } else { player.getInventory().clear(); player.getInventory().setHelmet(null); player.getInventory().setChestplate(null); player.getInventory().setLeggings(null); player.getInventory().setBoots(null); } } /** * Teleports all players to specified location. * * @param location * destination location */ public void teleportPlayers(final Location location) { for (Player p : this.activePlayers) p.teleport(location); } /** * Returns boolean if is this arena prepeared for playing. * * @return whether is arena ready for playing */ public boolean isPrepeared() { return this.gameSpawn != null && this.minimumPlayers != 0; } /** * Tries to start countdown. */ private void tryStartCountdown() { if (this.activePlayers.size() >= this.minimumPlayers) this.startCountdown(); else this.onNotEnoughPlayers(); } /** * Tries to stop countdown. */ private void tryStopCountdown() { //Check if we can stop, once the countdown started. if (this.countdownCanCancel) { Pexel.getScheduler().cancelTask(this.countdownTaskId); this.onCountdownCancelled(); } } /** * Returns world that this arena exists. (Got from world in this.gameSpawn). * * @return world of this arena */ public World getWorld() { return this.gameSpawn.getWorld(); } private void startCountdown() { if (this.countdownTaskId == 0) { NetworkCCFormatter.sendCDstart(this); //Reset countdown time. this.countdownTimeLeft = this.countdownLenght; //Start countdown. this.countdownTaskId = Pexel.getScheduler().scheduleSyncRepeatingTask( new Runnable() { @Override public void run() { AdvancedArena.this.countdownTick(); } }, 0L, 20L); this.onCountdownStart(); } } private void onCountdownStop() { Pexel.getScheduler().cancelTask(this.countdownTaskId); NetworkCCFormatter.sendCDstop(this); } /** * Called once per second while countdown is running. */ private void countdownTick() { //Send a chat message. if (this.countdownTimeLeft < 10 || (this.countdownTimeLeft % 10) == 0) { this.chatAll(ChatManager.minigame( this.minigame, this.countdownFormat.replace("%timeleft%", Integer.toString(this.countdownTimeLeft)))); for (Player p : this.getPlayers()) { p.playSound(p.getLocation(), Sound.WOLF_GROWL, 1F, 1F); } } //If we are using boss bar. if (this.useBossBar) this.setBossBarAll( this.countdownFormat.replace("%timeleft%", Integer.toString(this.countdownTimeLeft)), this.countdownTimeLeft / this.countdownLenght * 100F); //If we reached zero. if (this.countdownTimeLeft <= 0) { //Remove bossbar if (this.useBossBar) for (Player p : this.activePlayers) BarAPI.removeBar(p); //Stop the countdown task. this.onCountdownStop(); //Start game. this.chatAll(ChatManager.minigame( this.getMinigame(), ChatColor.GREEN + "Map: " + ChatColor.WHITE + this.mapData.getName() + ChatColor.WHITE + " by " + ChatColor.RED + this.mapData.getAuthor())); this.onGameStart(); this.gameStarted = true; } // Set food level. for (Player p : this.getPlayers()) { p.setFoodLevel(20); } //Decrement the time. this.countdownTimeLeft -= 1; } /** * Set's boss bar content for all players. * * @param replace * message (max 40 char.) */ public void setBossBarAll(final String message) { for (Player p : this.activePlayers) { BarAPI.removeBar(p); BarAPI.setMessage(p, message); } } /** * Set's boss bar content for all players. * * @param replace * message (max 40 char.) */ public void setBossBarAll(final String message, final float percent) { for (Player p : this.activePlayers) { BarAPI.removeBar(p); BarAPI.setMessage(p, message, percent); } } /** * Reseta arena basic things. <b>Calls {@link AdvancedArena#onReset()} at the end of this function!</b></br> If you * want to extend reset function, override onReset() function. */ public final void reset() { this.state = GameState.RESETING; Log.info("Resetting arena " + this.areaName + "..."); for (Player p : new ArrayList<Player>(this.activePlayers)) { this.onPlayerLeft(p, DisconnectReason.KICK_BY_SERVER); } NetworkCCFormatter.send(NetworkCCFormatter.MSG_TYPE_ARENA_STATE, this, this.state.toString()); this.gameStarted = false; this.countdownTaskId = 0; //Not many things happeing here. Leaving method for future. this.activePlayers.clear(); //Invoke callback. this.onReset(); } /** * Called right after the arena resets it's basic things, after {@link AdvancedArena#reset()} was called. <b>Don't * forget to change arena's state to {@link GameState#WAITING_EMPTY} after reset.</b> */ public void onReset() { } /** * Called when countdown starts. */ public void onCountdownStart() { } /** * Called when countdown stops. */ public void onCountdownCancelled() { } /** * Called each time, a player joins arena and there is not enough players for countdown start. */ public void onNotEnoughPlayers() { } /** * Called when game should start its logic. Called when lobby countdown has reached zero and there is enough * players. */ public void onGameStart() { } /** * Called when last player lefts the arena. Should call {@link AdvancedArena#reset()} function if * <code>autoReset</code> is set to <b>false</b> (false by default). */ public void onGameEnd() { } /** * Called when players join the arena. Also checks if there are enough players, if so, calls * {@link AdvancedArena#onGameStart()}. If not, calls {@link AdvancedArena#onNotEnoughPlayers()}. */ @Override public void onPlayerJoin(final Player player) { if (!this.activePlayers.contains(player)) { super.onPlayerJoin(player); NetworkCCFormatter.sendPlayerJoin(this, player); this.tryStartCountdown(); // If enough players, start the game soon. if (this.getPlayerCount() == this.slots) { if (this.countdownTimeLeft > 10) this.countdownTimeLeft = 10; } this.updateGameState(); this.clearPlayerInventory(player); // Remove effects from lobbies. player.removePotionEffect(PotionEffectType.SPEED); player.removePotionEffect(PotionEffectType.JUMP); // TODO: Should use template instead of hardcoding message style. this.chatAll(ChatManager.minigame(this.getMinigame(), ChatColor.GOLD + "Player '" + player.getName() + "' joined arena! (" + this.getPlayerCount() + "/" + this.minimumPlayers + " - " + this.slots + ")")); // Teleport player to arena spawn location. player.teleport(this.gameSpawn); } else { player.sendMessage(ChatManager.error("Alredy playing!")); } } /** * Called when player left the arena. If is arena in LOBBY/WAITING_PLAYERS state, and flag * {@link AdvancedArena#countdownCanCancel} is set to <b>true</b>, stops the countdown. */ @Override public void onPlayerLeft(final Player player, final DisconnectReason reason) { super.onPlayerLeft(player, reason); this.chatAll(ChatManager.minigame(this.getMinigame(), "Player '" + player.getName() + "' has left arena (" + reason.name() + ")!")); NetworkCCFormatter.sendPlayerLeft(this, player); this.tryStopCountdown(); this.checkForEnd(); // BarApi fix. if (BarAPI.hasBar(player)) BarAPI.removeBar(player); // Alway remove from spectating mode. if (this.isSpectating(player)) { this.setSpectating(player, false); } this.updateGameState(); // Clear player's inventory. this.clearPlayerInventory(player); } @EventHandler protected void onPlayerQuit(final PlayerQuitEvent event) { if (this.contains(event.getPlayer())) this.onPlayerLeft(event.getPlayer(), DisconnectReason.PLAYER_DISCONNECT); } /** * Updates game state. */ private void updateGameState() { if (!this.gameStarted) { if (this.getPlayerCount() == 0) this.state = GameState.WAITING_EMPTY; else this.state = GameState.WAITING_PLAYERS; } } /** * Checks if there are no players in arena, and if arena is in PLAYING state. If so, the * {@link AdvancedArena#onGameEnd()} */ private void checkForEnd() { if (this.activePlayers.size() <= 1 && this.state.isPlaying()) { this.onGameEnd(); if (this.autoReset) this.reset(); } } @EventHandler public void ___onPlayerRespawn(final PlayerRespawnEvent event) { if (this.contains(event.getPlayer())) if (!this.respawnAllowed) { //Kick from arena this.onPlayerLeft(event.getPlayer(), DisconnectReason.LEAVE_BY_GAME); } } @EventHandler public void onPlayerInventoryClick(final InventoryClickEvent event) { if (event.getWhoClicked() instanceof Player) { if (this.activePlayers.contains(event.getWhoClicked())) { if (this.inventoryDisabled) { event.setCancelled(true); } } } } public int getMinimalPlayers() { return this.minimumPlayers; } public void setMinimalPlayers(final int minimalPlayers) { this.minimumPlayers = minimalPlayers; } public int getCountdownLenght() { return this.countdownLenght; } public void setCountdownLenght(final int countdownLenght) { this.countdownLenght = countdownLenght; } /** * @deprecated Deprecated and removed, now returns only {@link Pexel#getHubLocation()}. * @return */ @Deprecated public Location getLobbyLocation() { return Pexel.getHubLocation(); } /** * Does nothing now. * * @deprecated Deprecated and removed. see {@link AdvancedArena#getLobbyLocation()} for explanamination. * @param lobbyLocation */ @Deprecated public void setLobbyLocation(final Location lobbyLocation) { //this.lobbyLocation = lobbyLocation; } public void setGameState(final GameState state) { this.state = state; } public Location getGameSpawn() { return this.gameSpawn; } public void setGameSpawn(final Location gameSpawn) { this.gameSpawn = gameSpawn; } public boolean countdownCanCancel() { return this.countdownCanCancel; } public void setCountdownCanCancel(final boolean countdownCanCancel) { this.countdownCanCancel = countdownCanCancel; } public boolean playersCanRespawn() { return this.respawnAllowed; } public void setPlayersCanRespawn(final boolean playersCanRespawn) { this.respawnAllowed = playersCanRespawn; } public int getCountdownTimeLeft() { return this.countdownTimeLeft; } public String getCountdownFormat() { return this.countdownFormat; } public void setCountdownFormat(final String countdownFormat) { this.countdownFormat = countdownFormat; } }
17,933
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
MapData.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/MapData.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; import java.io.File; import java.util.HashMap; import java.util.Map; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.bukkit.Location; import org.bukkit.World; import eu.matejkormuth.pexel.PexelCore.core.Region; import eu.matejkormuth.pexel.PexelCore.core.RegionTransformer; import eu.matejkormuth.pexel.PexelCore.util.SerializableLocation; /** * Class that represents data of playable map (not block data). */ @XmlType(name = "arenamap") @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement public class MapData { // Keys /** * Minimum number of players required to start arena. */ public static transient final String KEY_MINIMAL_PLAYERS = "minimalplayers"; /** * Length of countdown in seconds, when minimal amount of players joined arena. */ public static transient final String KEY_COUNTDOWN_LENGHT = "countdownlength"; /** * Length of countdown in seconds, when minimal amount of players joined arena. */ public static transient final String KEY_ARENA_SPAWN = "spawn"; @XmlAttribute(name = "name") protected String name; @XmlAttribute(name = "minigameName") protected String minigameName; @XmlAttribute(name = "author") protected String author; @XmlElementWrapper(name = "options_text") protected final Map<String, String> options_string = new HashMap<String, String>(); @XmlElementWrapper(name = "options_number") protected final Map<String, Integer> options_int = new HashMap<String, Integer>(); @XmlElementWrapper(name = "locations") protected final Map<String, SerializableLocation> locations = new HashMap<String, SerializableLocation>(); @XmlElementWrapper(name = "regions") protected final Map<String, Region> regions = new HashMap<String, Region>(); @XmlAttribute(name = "locationsType") protected LocationsType locationsType = LocationsType.ABSOLUTE; @XmlAttribute(name = "maxPlayers") protected int maxPlayers = 16; // Default value of 16. @XmlAttribute(name = "protectedRegion") protected Region protectedRegion; @XmlElement(name = "anchor") // Used only if locationsType is RELATIVE. protected SerializableLocation anchor = null; /** * Creates a new MapData with specified author and name. * * @param name * name of map * @param author * author of map */ public MapData(final String name, final String author) { this.name = name; this.author = author; } /** * Initialization method for {@link AdvancedArena} classes. */ public void init(final int maxPlayers, final int minPlayers, final int countdownLength, final Location spawnLocation, final Region protectedRegion) { this.maxPlayers = maxPlayers; this.options_int.put(MapData.KEY_COUNTDOWN_LENGHT, countdownLength); this.options_int.put(MapData.KEY_MINIMAL_PLAYERS, minPlayers); this.locations.put(MapData.KEY_ARENA_SPAWN, new SerializableLocation( spawnLocation)); this.protectedRegion = protectedRegion; } public MapData() { } public static final MapData load(final File file) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(MapData.class); Unmarshaller un = jc.createUnmarshaller(); return (MapData) un.unmarshal(file); } public void save(final File file) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(MapData.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(this, file); } /** * Returns boolean whether this mapData is usable in specified arena. * * @param arena * arena to check * @return true or false */ public boolean validate(final AbstractArena arena) { return arena.getMinigame().getName().equals(this.minigameName); } public String getOption_String(final String key) { return this.options_string.get(key); } public int getOption_Integer(final String key) { return this.options_int.get(key); } public String getMinigameName() { return this.minigameName; } public String getName() { return this.name; } public String getAuthor() { return this.author; } public Location getLocation(final String key) { if (this.locationsType == LocationsType.ABSOLUTE) { return this.locations.get(key).getLocation(); } else { if (this.anchor != null) { return this.anchor.getLocation().add( this.locations.get(key).getLocation()); } else { throw new InvalidMapDataException( "Can't return relatiive location when anchor is null."); } } } public Region getRegion(final String key) { if (this.locationsType == LocationsType.ABSOLUTE) { return this.regions.get(key); } else { return RegionTransformer.toAbsolute(this.regions.get(key), this.anchor.getLocation()); } } public Map<String, String> getOptionsString() { return this.options_string; } public Map<String, Integer> getOptionsNumber() { return this.options_int; } public Map<String, SerializableLocation> getLocations() { return this.locations; } public Map<String, Region> getRegions() { return this.regions; } public Region getProtectedRegion() { return this.protectedRegion; } // Bukkit impl; will take care of it later. public World getWorld() { return this.protectedRegion.getWorld(); } public int getMaxPlayers() { return this.maxPlayers; } }
7,886
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
DisconnectReason.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/DisconnectReason.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; /** * Reasons for disconnecting from arena. */ public enum DisconnectReason { /** * Player has invoked disconnect from server. */ PLAYER_DISCONNECT, /** * Player has lost connection to server. */ PLAYER_CONNECTION_LOST, /** * Player has used /leave command or left by his decision. */ PLAYER_LEAVE, /** * Invoked by game (eg. player has lost match). */ LEAVE_BY_GAME, /** * Invoked by admin (eg. kicked for violating rules). */ KICK_BY_SERVER, /** * Unknown or other reason. (Avoid using this one) */ UNKNOWN, }
1,496
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
AbstractArena.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/AbstractArena.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; import java.io.File; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.bukkit.ChatColor; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.areas.ProtectedArea; import eu.matejkormuth.pexel.PexelCore.bans.BanUtils; import eu.matejkormuth.pexel.PexelCore.bans.Bannable; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Log; import eu.matejkormuth.pexel.PexelCore.core.PlayerHolder; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; import eu.matejkormuth.pexel.PexelCore.core.ValidityChecker; import eu.matejkormuth.pexel.PexelCore.matchmaking.GameState; import eu.matejkormuth.pexel.PexelCore.matchmaking.MatchmakingGame; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; import eu.matejkormuth.pexel.PexelCore.util.ItemUtils; /** * Abstract minigame arena - {@link ProtectedArea} that implements {@link MatchmakingGame}, {@link PlayerHolder}, * {@link Bannable}. Contains some useful functions and basic strucutre of minigame. */ public abstract class AbstractArena extends ProtectedArea implements MatchmakingGame, PlayerHolder, Bannable { /** * Number of actual maximum number of players. May be changed at runtime, so it does not reflect max. player from * {@link MapData}. */ protected int slots; /** * The actual state of the arena. */ protected GameState state = GameState.WAITING_PLAYERS; /** * The game mode that players should get, when they join the game. */ protected GameMode defaultGameMode = GameMode.ADVENTURE; /** * List of active players in arena. */ protected final List<Player> activePlayers = new ArrayList<Player>(); /** * List of spectating players in arena. */ protected final List<Player> spectatingPlayers = new ArrayList<Player>(); /** * Reference to minigame. */ protected final Minigame minigame; /** * {@link MapData} that is currenlty played on this arena. */ protected MapData mapData; public AbstractArena(final Minigame minigame, final String arenaName, final MapData mapData) { super(minigame.getName() + "_" + arenaName, mapData.getProtectedRegion()); this.minigame = minigame; this.slots = mapData.getMaxPlayers(); this.mapData = mapData; // Check MapData validity. ValidityChecker.checkMapData(mapData); } /** * Sends a chat message to all player in arena. * * @param msg * message to be send */ public void chatAll(final String msg) { for (Player p : this.activePlayers) { p.sendMessage(msg); } } @Override public int getFreeSlots() { return this.slots - this.activePlayers.size(); } @Override public int getMaximumSlots() { return this.slots; } @Override public GameState getState() { return this.state; } @Override public List<Player> getPlayers() { return this.activePlayers; } @Override public boolean canJoin() { return this.getFreeSlots() >= 1 && (this.state == GameState.WAITING_PLAYERS || this.state == GameState.WAITING_EMPTY || this.state == GameState.PLAYING_CANJOIN); } @Override public boolean canJoin(final int count) { return this.getFreeSlots() >= count && (this.state == GameState.WAITING_PLAYERS || this.state == GameState.WAITING_EMPTY || this.state == GameState.PLAYING_CANJOIN); } @Override public void onPlayerJoin(final Player player) { if (Pexel.getBans().isBanned(player, this)) { player.sendMessage(ChatManager.error(BanUtils.formatBannedMessage(Pexel.getBans().getBan( player, this)))); } else { this.activePlayers.add(player); player.setGameMode(this.defaultGameMode); } } @Override public void onPlayerLeft(final Player player, final DisconnectReason reason) { this.activePlayers.remove(player); } /** * Plays sound for all players in arena. * * @param sound * sound to play * @param volume * volume * @param pitch * pitch */ public void playSoundAll(final Sound sound, final float volume, final float pitch) { for (Player p : this.activePlayers) p.playSound(p.getLocation(), sound, volume, pitch); } /** * Sets spectating mode for player in this arena. * * @param player * player * @param spectating * the value if the player should be spectating or not. */ public void setSpectating(final Player player, final boolean spectating) { if (spectating) { if (!StorageEngine.getProfile(player.getUniqueId()).isSpectating()) { player.sendMessage(ChatManager.success("You are now spectating!")); StorageEngine.getProfile(player.getUniqueId()).setSpectating(true); player.getInventory().clear(); player.getInventory().addItem( ItemUtils.namedItemStack(Material.COMPASS, ChatColor.YELLOW + "Spectating", null)); player.setGameMode(GameMode.ADVENTURE); player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0)); player.setAllowFlight(true); player.setFlying(true); this.spectatingPlayers.add(player); } else { //Player is already spectating. Log.warn("Player '" + player.getName() + "' can't be moved to spectating mode by game '" + this.getMinigame().getName() + "': Player is already in spectating mode!"); } } else { if (StorageEngine.getProfile(player.getUniqueId()).isSpectating()) { player.sendMessage(ChatManager.success("You are no longer spectating!")); StorageEngine.getProfile(player.getUniqueId()).setSpectating(false); player.getInventory().clear(); player.setGameMode(this.defaultGameMode); player.removePotionEffect(PotionEffectType.NIGHT_VISION); player.removePotionEffect(PotionEffectType.INVISIBILITY); player.setAllowFlight(false); player.setFlying(false); this.spectatingPlayers.remove(player); } else { //Player is not spectating. Log.warn("Player '" + player.getName() + "' can't be moved from spectating mode by game '" + this.getMinigame().getName() + "': Player is not in spectating mode!"); } } } /** * Returns whether is specified player in spectator mode or not. * * @param player * player to check * @return true or false */ public boolean isSpectating(final Player player) { return StorageEngine.getProfile(player.getUniqueId()).isSpectating() || false; } /** * Returns whether is arena empty. * * @return true if arena is empty */ public boolean empty() { return this.activePlayers.size() == 0; } /** * Kicks all players from arena. Uses KICK_BY_GAME as {@link DisconnectReason} */ public void kickAll() { // Iteration problem, pls fix. - fixed. for (Player p : new ArrayList<Player>(this.activePlayers)) { this.onPlayerLeft(p, DisconnectReason.LEAVE_BY_GAME); } } /** * Sends a message to all players and kicks them. Uses KICK_BY_GAME as {@link DisconnectReason} * * @param message * message to send */ public void kickAll(final String message) { // Iteration problem, pls fix. -31.10.2014 fixed /mato for (Player p : new ArrayList<Player>(this.activePlayers)) { p.sendMessage(message); this.onPlayerLeft(p, DisconnectReason.LEAVE_BY_GAME); } } /** * Return minigame that is played in this arena. * * @return the minigame */ public Minigame getMinigame() { return this.minigame; } /** * @deprecated Use {@link MapData} and its saving / loading for saving or loading arena data. * @param path */ @Deprecated public void save(final String path) { try { Document conf = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = conf.createElement("aconfig"); conf.appendChild(root); Element info = conf.createElement("info"); root.appendChild(info); Element options = conf.createElement("options"); for (Field f : this.getClass().getDeclaredFields()) if (f.isAnnotationPresent(ArenaOption.class)) { ArenaOption annotation = f.getAnnotation(ArenaOption.class); Element option = conf.createElement("option"); option.setAttribute("name", f.getName()); option.setAttribute("type", f.getType().getCanonicalName()); option.setAttribute("annotation", annotation.name()); option.setAttribute("persistent", Boolean.toString(annotation.persistent())); if (!f.isAccessible()) f.setAccessible(true); if (f.getType().equals(Location.class)) { f.setAccessible(true); option.setTextContent(f.get(this).toString()); } else { option.setTextContent(f.get(this).toString()); } options.appendChild(option); } root.appendChild(options); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(conf); StreamResult result = new StreamResult(new File(path)); transformer.transform(source, result); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } catch (DOMException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } /** * Set's number of slots at runtime. Does not reflect / or change value in {@link MapData} config. * * @param slots * new number of slots */ public void setSlots(final int slots) { this.slots = slots; } /** * Set's current state to specified state. * * @param stateToSet */ public void setState(final GameState stateToSet) { this.state = stateToSet; } @Override public int getPlayerCount() { return this.activePlayers.size(); } @Override public boolean contains(final Player player) { return this.activePlayers.contains(player); } @Override public String getBannableID() { return "MA-" + this.areaName; } @Override public String getBannableName() { return this.getMinigame().getDisplayName() + " - " + this.areaName; } }
14,142
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
InvalidMapDataException.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/arenas/InvalidMapDataException.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.arenas; /** * Base exception for invalid {@link MapData}. */ public class InvalidMapDataException extends RuntimeException { private static final long serialVersionUID = -4753376360641192951L; public InvalidMapDataException(final String string) { super(string); } }
1,159
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BlockChange.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/rollback/BlockChange.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.rollback; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.material.MaterialData; /** * Class that stores information about change in blocks. * * @author Mato Kormuth * */ public class BlockChange { //Values before change. private final Material oldMaterial; private final MaterialData oldMaterialData; //Location. private final Location blockLocation; /** * Creates a new block change object. * * @param oldMaterial * old material * @param oldMaterialData * old data * @param blockLocation * location of block. */ public BlockChange(final Material oldMaterial, final MaterialData oldMaterialData, final Location blockLocation) { this.oldMaterial = oldMaterial; this.oldMaterialData = oldMaterialData; this.blockLocation = blockLocation; } /** * Creates a new block change from Block. * * @param block * the state of block before change */ public BlockChange(final Block block) { this.oldMaterial = block.getType(); this.oldMaterialData = block.getState().getData(); this.blockLocation = block.getLocation(); } /** * Changes block to its state before change. */ public void applyRollback() { BlockState state = this.blockLocation.getBlock().getState(); state.setType(this.oldMaterial); state.setData(this.oldMaterialData); state.update(true, false); //Do not apply physics on rollbacks. } /** * Returns the location of block. * * @return the location */ public Location getLocation() { return this.blockLocation; } }
2,726
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BlockRollbacker.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/rollback/BlockRollbacker.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.rollback; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bukkit.Location; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * Block rollbacker. * * @author Mato Kormuth * */ public class BlockRollbacker { //List of changes. private final List<BlockChange> changes = new ArrayList<BlockChange>(); //List of location changes. private final List<Location> changeLocations = new ArrayList<Location>(); //Bukkit task id. private int taskId = 0; //Runnable to be run after async rollback. private Runnable onFinished; //Max block changes per one game tick. private int maxChangesPerTick = 128; /** * Registers a change to this rollbacker. * * @param change */ public void addChange(final BlockChange change) { if (!this.changeLocations.contains(change.getLocation())) { this.changes.add(change); this.changeLocations.add(change.getLocation()); } } /** * Reverts all registered changes right after call of this function. (Not recomended) */ public void rollback() { for (Iterator<BlockChange> iterator = this.changes.iterator(); iterator.hasNext();) { BlockChange change = iterator.next(); change.applyRollback(); this.changeLocations.remove(change.getLocation()); iterator.remove(); } } /** * Starts a task for rollbacking with default (128) amount of blocks reverted in one tick. * * @param onFinished * runnable, that should be called after the rollback is done. */ public void rollbackAsync(final Runnable onFinished) { this.onFinished = onFinished; this.taskId = Pexel.getScheduler().scheduleSyncRepeatingTask(new Runnable() { @Override public void run() { BlockRollbacker.this.doRollback(); } }, 0L, 1L); } /** * Starts a task for rollbacking with specified amount of blocks reverted in one tick. * * @param onFinished * runnable, that should be called after the rollback is done. */ public void rollbackAsync(final Runnable onFinished, final int maxIterations) { this.maxChangesPerTick = maxIterations; this.rollbackAsync(onFinished); } /** * Performs one rollback (rollbacks this.maxChangesPerTick blocks). */ private void doRollback() { if (this.changes.size() == 0) { Pexel.getScheduler().cancelTask(this.taskId); if (this.onFinished != null) this.onFinished.run(); } else { int count = 0; for (Iterator<BlockChange> iterator = this.changes.iterator(); iterator.hasNext();) { if (count > this.maxChangesPerTick) break; else { BlockChange bc = iterator.next(); this.changeLocations.remove(bc.getLocation()); bc.applyRollback(); iterator.remove(); } count++; } } } }
4,175
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ScoreboardView.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/scoreboard/ScoreboardView.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.scoreboard; import org.bukkit.scoreboard.Scoreboard; /** * Class that specifies, that this class could be used with scoreboard manager. * * @author Mato Kormuth * */ public interface ScoreboardView { /** * Returns scoreboard object. * * @return the scoreboard objects */ public Scoreboard getScoreboard(); /** * Resets scoreboard. */ public void reset(); }
1,283
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ScoreboardManager.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/scoreboard/ScoreboardManager.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.scoreboard; import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** * Manager for scoreboard. * * @author Mato Kormuth * */ public class ScoreboardManager { private final ScoreboardView scoreboard; /** * Creates new scoreboard manager, with specified scoreboard. * * @param scoreboard */ public ScoreboardManager(final ScoreboardView scoreboard) { this.scoreboard = scoreboard; } /** * Adds player to this manager. * * @param p * player */ public void addPlayer(final Player p) { p.setScoreboard(this.scoreboard.getScoreboard()); } /** * Removes player from this scoreboard manager. * * @param p * player */ public void removePlayer(final Player p) { p.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard()); } /** * Resets wrapper. */ public void reset() { this.scoreboard.reset(); } }
1,887
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
TextScoreboard.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/scoreboard/TextScoreboard.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.scoreboard; import java.util.HashMap; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Scoreboard; public class TextScoreboard implements ScoreboardView { /** * Mapping scores. */ private final Map<String, Score> scores = new HashMap<String, Score>(); /** * Scoreboard. */ private final Scoreboard board; /** * Objective. */ private final Objective objective; /** * Creates a new simle player-score scoreboard. * * @param name * name of objective * @param title * title of scoreboard */ public TextScoreboard(final String name, final String title) { this.board = Bukkit.getScoreboardManager().getNewScoreboard(); this.objective = this.board.registerNewObjective(name, "dummy"); this.objective.setDisplayName(title); this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); } /** * Sets player's score to specified amount. * * @param key * string key * @param amount * amount to set */ public void setScore(final String key, final int amount) { if (this.scores.containsKey(key)) this.scores.get(key).setScore(amount); else { this.scores.put(key, this.objective.getScore(key)); this.scores.get(key).setScore(amount); } } /** * Increments score for specified player with specified amount. * * @param key * string key * @param amount * amount to incerement */ public void incrementScore(final String key, final int amount) { if (this.scores.containsKey(key)) this.scores.get(key).setScore(this.scores.get(key).getScore() + amount); else { this.scores.put(key, this.objective.getScore(key)); this.scores.get(key).setScore(amount); } } /** * Resets scoreboard. */ @Override public void reset() { for (Score s : this.scores.values()) s.setScore(0); this.scores.clear(); } @Override public Scoreboard getScoreboard() { return this.board; } /** * Clears scoreboard. */ public void clear() { this.reset(); } }
3,376
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
SimpleScoreboard.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/scoreboard/SimpleScoreboard.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.scoreboard; import java.util.HashMap; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Scoreboard; /** * Simple one score per player scoreboard. * * @author Mato Kormuth * */ public class SimpleScoreboard implements ScoreboardView { /** * Mapping scores. */ private final Map<Player, Score> scores = new HashMap<Player, Score>(); /** * Scoreboard. */ private final Scoreboard board; /** * Objective. */ private final Objective objective; /** * Creates a new simle player-score scoreboard. * * @param name * name of objective * @param title * title of scoreboard */ public SimpleScoreboard(final String name, final String title) { this.board = Bukkit.getScoreboardManager().getNewScoreboard(); this.objective = this.board.registerNewObjective(name, "dummy"); this.objective.setDisplayName(title); this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); } /** * Sets player's score to specified amount. * * @param player * @param amount */ public void setScore(final Player player, final int amount) { if (this.scores.containsKey(player)) this.scores.get(player).setScore(amount); else { this.scores.put(player, this.objective.getScore(player.getName())); this.scores.get(player).setScore(amount); } } /** * Increments score for specified player with specified amount. * * @param player * player * @param amount * amount to incerement */ public void incrementScore(final Player player, final int amount) { if (this.scores.containsKey(player)) this.scores.get(player).setScore(this.scores.get(player).getScore() + amount); else { this.scores.put(player, this.objective.getScore(player.getName())); this.scores.get(player).setScore(amount); } } /** * Resets scoreboard. */ @Override public void reset() { for (Score s : this.scores.values()) s.setScore(0); this.scores.clear(); } @Override public Scoreboard getScoreboard() { return this.board; } }
3,395
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ChatManager.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/ChatManager.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.player.AsyncPlayerChatEvent; import eu.matejkormuth.pexel.PexelCore.core.Log; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Union chat formatter and manager for pexel. * * @author Mato Kormuth * */ public class ChatManager { private static final String minigameFormat = ChatColor.DARK_GREEN + "[%minigame%] " + ChatColor.WHITE + " %msg%"; private static final String errorFormat = ChatColor.RED + "%msg%"; private static final String successFormat = ChatColor.GREEN + "%msg%"; private static final String chatDefaultFormat = ChatColor.GRAY + "%player% > %msg%"; private static final String chatOpFormat = ChatColor.GOLD + "[OP] %player% > %msg%"; private static final Map<String, ChatChannel> channels = new HashMap<String, ChatChannel>(); public static final ChatChannel CHANNEL_GLOBAL = new ChatChannel( "global", ChatColor.GOLD + "[GLOBAL]", false); public static final ChatChannel CHANNEL_OP = new ChatChannel( "op", "[OP] "); public static final ChatChannel CHANNEL_LOG = new ChatChannel( "log", ChatColor.GRAY + "[LOG] "); public static final ChatChannel CHANNEL_NETWORK = new ChatChannel( "network", ChatColor.GRAY.toString() + ChatColor.ITALIC + "[NET] "); public static final ChatChannel CHANNEL_LOBBY = new ChatChannel( "lobby", ChatColor.GRAY.toString()); private static final long CHANNEL_LIFETIME = 1000 * 60 * 60 * 24; //One day public static final String error(final String msg) { return ChatManager.errorFormat.replace("%msg%", msg); } public static final String success(final String msg) { return ChatManager.successFormat.replace("%msg%", msg); } public static final String chatPlayer(final String msg, final Player player) { return ChatManager.chatDefaultFormat.replace("%player%", player.getDisplayName()).replace( "%msg%", msg); } public static final String chatPlayerOp(final String msg, final Player player) { return ChatManager.chatOpFormat.replace("%player%", player.getDisplayName()).replace( "%msg%", msg); } public static final String chatPlayerFriend(final String msg, final Player player) { return ChatColor.BLUE + ChatManager.chatDefaultFormat.replace("%player%", player.getDisplayName()).replace("%msg%", msg); } /** * Returns formatted 'minigame' message. * * @param minigame * minigame * @param msg * message to format * @return formatted message */ public static final String minigame(final Minigame minigame, final String msg) { return ChatManager.minigameFormat.replace("%minigame%", minigame.getDisplayName()).replace("%msg%", msg); } /** * Registers chat channel. * * @param chatChannel * channel to register */ public static void registerChannel(final ChatChannel chatChannel) { if (!ChatManager.channels.containsKey(chatChannel.getName())) ChatManager.channels.put(chatChannel.getName(), chatChannel); else throw new RuntimeException("Chat channel with name '" + chatChannel.getName() + "' is already registered!"); } /** * Unregisters player from channel. * * @param channelName * channel name * @param player * player */ public static void unregisterFromChannel(final String channelName, final Player player) { if (ChatManager.channels.containsKey(channelName)) ChatManager.channels.get(channelName).unsubscribe(player); else throw new RuntimeException("Chat channel not found!"); } /** * Unregisters subscriber from channel. * * @param channelName * channel name * @param subscriber * subscriber */ public static void unregisterFromChannel(final String channelName, final ChannelSubscriber subscriber) { if (ChatManager.channels.containsKey(channelName)) ChatManager.channels.get(channelName).unsubscribe(subscriber); else throw new RuntimeException("Chat channel not found!"); } /** * Removes old, unused channels. */ public static void cleanUpChannels() { for (ChatChannel channel : ChatManager.channels.values()) if (channel.getLastActivity() + ChatManager.CHANNEL_LIFETIME < System.currentTimeMillis()) ChatManager.channels.remove(channel.getName()); } /** * Called when manager should manage chat event. * * @param event * chat event */ public static void __processChatEvent(final AsyncPlayerChatEvent event) { if (event.getMessage().trim().startsWith("@")) { String channelName = event.getMessage().substring(1, event.getMessage().indexOf(" ")).replace(":", ""); for (ChatChannel channel : ChatManager.channels.values()) if (channel.getName().equalsIgnoreCase(channelName)) if (channel.canWrite(event.getPlayer())) channel.broadcastMessage(event.getMessage()); } for (ChatChannel channel : ChatManager.channels.values()) if (channel.canWrite(event.getPlayer())) channel.broadcastMessage(event.getPlayer().getDisplayName() + " > " + event.getMessage()); Log.chat(event.getPlayer().getName() + ": " + event.getMessage()); event.setCancelled(true); } /** * Returns channel by name or null. * * @param channelName * name of channel */ public static ChatChannel getChannel(final String channelName) { if (ChatManager.channels.containsKey(channelName)) return ChatManager.channels.get(channelName); else return null; } /** * Returns channels that player is in. * * @param player * player to look for * @return list of channels */ public static List<ChatChannel> getChannelsByPlayer(final Player player) { List<ChatChannel> list = new ArrayList<ChatChannel>(); for (ChatChannel cch : ChatManager.channels.values()) if (cch.isSubscribed(player)) list.add(cch); return list; } }
9,707
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ChatChannel.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/ChatChannel.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.core.Settings; /** * Class specifing chat channel. * * @author Mato Kormuth * */ public class ChatChannel { public static final String UNSUBCRIBE_MSG = ChatColor.LIGHT_PURPLE + "You have left '%name%' chat channel!"; public static final String SUBCRIBE_MSG = ChatColor.LIGHT_PURPLE + "You have joined '%name%' chat channel with mode %mode% !"; //Last "random" channel ID. private static AtomicLong randomId = new AtomicLong(0L); /** * Name of channel. */ private final String name; /** * List of subscribers. */ private final List<ChannelSubscriber> subscribers = new ArrayList<ChannelSubscriber>(); /** * Prefix of this channel. */ private String prefix = ""; /** * Date of last activity in this channel. */ private long lastActivity = Long.MAX_VALUE; /** * Specifies if channel is visible to everyone. */ private boolean isPublic = true; /** * Creates new chat channel with specified name. * * @param name * name of channel */ public ChatChannel(final String name) { this.name = name; ChatManager.registerChannel(this); } public ChatChannel(final String name, final String prefix) { this.name = name; this.prefix = prefix; ChatManager.registerChannel(this); } public ChatChannel(final String name, final String prefix, final boolean writable) { this.name = name; this.prefix = prefix; ChatManager.registerChannel(this); } public ChatChannel(final String name, final boolean writable) { this.name = name; ChatManager.registerChannel(this); } /** * Subscribes player to this chat channel. * * @param player * player */ public void subscribe(final Player player, final SubscribeMode mode) { this.subscribers.add(new PlayerChannelSubscriber(player, mode)); player.sendMessage(ChatChannel.SUBCRIBE_MSG.replace("%name%", this.getName()).replace( "%mode%", mode.toString())); } /** * Subscribes subscriber to this chat channel. * * @param subscriber * subscriber to be added to this channel */ public void subscribe(final ChannelSubscriber subscriber) { this.subscribers.add(subscriber); subscriber.sendMessage(ChatChannel.SUBCRIBE_MSG.replace("%name%", this.getName()).replace( "%mode%", subscriber.getMode().toString())); } /** * Unsubscribes player from this chat channel. * * @param player * specified player */ public void unsubscribe(final Player player) { for (Iterator<ChannelSubscriber> iterator = this.subscribers.iterator(); iterator.hasNext();) { ChannelSubscriber subscriber = iterator.next(); if (subscriber instanceof PlayerChannelSubscriber) if (((PlayerChannelSubscriber) subscriber).getPlayer() == player) iterator.remove(); } player.sendMessage(ChatChannel.UNSUBCRIBE_MSG.replace("%name%", this.getName())); } /** * Unsubscribes specified subscriber from this channel. If the subscriber did not subscribed to this channel, * nothing happens. * * @param subscriber * subscrber to be unregistered */ public void unsubscribe(final ChannelSubscriber subscriber) { this.subscribers.remove(subscriber); subscriber.sendMessage(ChatChannel.UNSUBCRIBE_MSG.replace("%name%", this.getName())); } /** * Retruns true, if specified subscriber is subscribed. * * @param subscriber * subscriber to check */ public boolean isSubscribed(final ChannelSubscriber subscriber) { return this.subscribers.contains(subscriber); } /** * Returns whether player can read messages from this channel. * * @param player * player to check * @return true if player can read */ public boolean canRead(final Player player) { for (ChannelSubscriber subscriber : this.subscribers) if (subscriber instanceof PlayerChannelSubscriber) if (((PlayerChannelSubscriber) subscriber).getPlayer() == player) return this.canRead(subscriber); return false; } /** * Returns whether subscriber can read messages from this channel. * * @param uuid * player to check * @return true if player can read */ public boolean canRead(final ChannelSubscriber subscriber) { return this.subscribers.contains(subscriber); } /** * Sends message to all subscribers. * * @param message * message to be send */ public void broadcastMessage(String message) { this.lastActivity = System.currentTimeMillis(); // Support for colored messages message = ChatColor.translateAlternateColorCodes("&".toCharArray()[0], message); for (Iterator<ChannelSubscriber> iterator = this.subscribers.iterator(); iterator.hasNext();) { ChannelSubscriber p = iterator.next(); if (p.isOnline()) if (message.toLowerCase().contains(p.getName().toLowerCase()) && !message.startsWith(p.getName().toLowerCase())) { p.sendMessage(this.prefix + ChatColor.BLUE + message); if (p instanceof PlayerChannelSubscriber) if (Settings.CHAT_SOUNDS.hasEnabled(((PlayerChannelSubscriber) p).getPlayer())) ((PlayerChannelSubscriber) p).getPlayer().playSound( ((PlayerChannelSubscriber) p).getPlayer().getLocation(), Sound.NOTE_STICKS, 0.5F, 1); } else { p.sendMessage(this.prefix + message); } else iterator.remove(); } } /** * Returns name of channel. * * @return the name of channel */ public String getName() { return this.name; } /** * Returns if player can write to this channel. * * @param player * @return true if player can write */ public boolean canWrite(final Player player) { for (ChannelSubscriber subscriber : this.subscribers) if (subscriber instanceof PlayerChannelSubscriber) if (((PlayerChannelSubscriber) subscriber).getPlayer() == player) return this.canWrite(subscriber); return false; } /** * Returns if player can write to this channel. * * @param subscriber * specified subscriber * @return true if player can write */ public boolean canWrite(final ChannelSubscriber subscriber) { if (!this.subscribers.contains(subscriber)) return false; else { return subscriber.getMode() == SubscribeMode.READ_WRITE; } } /** * Returns random new channel, without specified name and stuff. * * @return random chat channel */ public static ChatChannel createRandom() { return new ChatChannel("r" + ChatChannel.randomId.getAndIncrement()); } /** * Set's channels prefix. */ public void setPrefix(final String prefix) { this.prefix = prefix; } /** * @return the lastActivity */ public long getLastActivity() { return this.lastActivity; } /** * @param player */ public boolean isSubscribed(final Player player) { for (ChannelSubscriber subscriber : this.subscribers) if (subscriber instanceof PlayerChannelSubscriber) if (((PlayerChannelSubscriber) subscriber).getPlayer() == player) return true; return false; } /** * Returns whether this channel is public. */ public boolean isPublic() { return this.isPublic; } /** * @param isPublic * the isPublic to set */ public void setPublic(final boolean isPublic) { this.isPublic = isPublic; } }
9,908
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ChannelSubscriber.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/ChannelSubscriber.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; /** * Interface definating the chat channel subscriber. * * @author Mato Kormuth * */ public interface ChannelSubscriber { /** * Sends message to this subscriber. * * @param message * message to be send */ public void sendMessage(String message); /** * Returns this subscriber's mode. * * @return subscribe mode */ public SubscribeMode getMode(); /** * Returns if is this subscriber online/active. * * @return whether the player is online or not */ public boolean isOnline(); /** * Returns name of channel subscriber. * * @return name of subscriber */ public String getName(); }
1,605
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ChatMessage.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/ChatMessage.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; import org.bukkit.ChatColor; /** * Class that represents chat message. */ public class ChatMessage { private String rawMessage; private ChannelSubscriber sender; /** * @param rawMessage * @param sender */ public ChatMessage(final String rawMessage, final ChannelSubscriber sender) { this.rawMessage = rawMessage; this.sender = sender; } /** * @return the rawMessage */ public String getRawMessage() { return this.rawMessage; } /** * @param rawMessage * the rawMessage to set */ public void setRawMessage(final String rawMessage) { this.rawMessage = rawMessage; } /** * @return the sender */ public ChannelSubscriber getSender() { return this.sender; } /** * @param sender * the sender to set */ public void setSender(final ChannelSubscriber sender) { this.sender = sender; } public String getFormattedMessage() { return ChatColor.GRAY + this.sender.getName() + " > " + this.rawMessage; } }
2,025
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PlayerChannelSubscriber.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/PlayerChannelSubscriber.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; import org.bukkit.entity.Player; /** * Chat channel subscriber. * * @author Mato Kormuth * */ public class PlayerChannelSubscriber implements ChannelSubscriber { private final SubscribeMode mode; private final Player player; /** * Creates new instance of player channel subscriber. * * @param player * player * @param mode * subscribe mode */ public PlayerChannelSubscriber(final Player player, final SubscribeMode mode) { this.mode = mode; this.player = player; } /** * Returns subscription mode. * * @return subscription mode */ @Override public SubscribeMode getMode() { return this.mode; } /** * Sends message to this subscriber. * * @param message * message to send */ @Override public void sendMessage(final String message) { this.player.sendMessage(message); } @Override public boolean isOnline() { return this.player.isOnline(); } /** * Returns the player to which is this subscriber associated. * * @return player object */ public Player getPlayer() { return this.player; } @Override public String getName() { return this.player.getName(); } }
2,251
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
SubscribeMode.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/chat/SubscribeMode.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.chat; /** * Chat channel subscription mode. * * @author Mato Kormuth * */ public enum SubscribeMode { /** * Player can only read (receive) messages from channel. (default) */ READ, /** * Player can read (receive) and write (send) messages to channel. */ READ_WRITE; }
1,177
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Kit.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/kits/Kit.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.kits; import java.util.List; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; /** * Class used for applying kits on players. * * @author Mato Kormuth * */ public class Kit { private final List<ItemStack> items; private ItemStack helmet; private ItemStack chestplate; private ItemStack leggings; private ItemStack boots; private final ItemStack icon; /** * Creates a new kit with specified items. * * @param items * items in inventory */ public Kit(final List<ItemStack> items, final ItemStack icon) { this.items = items; this.icon = icon; } /** * Creates a new kit with specified armor and items. * * @param items * items in inventory * @param helmet * @param chestplate * @param leggings * @param boots */ public Kit(final List<ItemStack> items, final ItemStack icon, final ItemStack helmet, final ItemStack chestplate, final ItemStack leggings, final ItemStack boots) { this.items = items; this.icon = icon; this.helmet = helmet; this.chestplate = chestplate; this.leggings = leggings; this.boots = boots; } /** * Applies kit on specified player, removing all previous items. * * @param player * player to give kit to */ public void applyKit(final Player player) { player.getInventory().clear(); //FIX: If kit contains no armor, the armor from previous kit would be preserved. //player.getInventory().setHelmet(null); //player.getInventory().setChestplate(null); //player.getInventory().setLeggings(null); //player.getInventory().setBoots(null); if (this.helmet != null) player.getInventory().setHelmet(this.helmet); if (this.chestplate != null) player.getInventory().setChestplate(this.chestplate); if (this.leggings != null) player.getInventory().setLeggings(this.leggings); if (this.boots != null) player.getInventory().setBoots(this.boots); for (ItemStack itemstack : this.items) player.getInventory().addItem(itemstack); } /** * Returns item stack of this kit icon. * * @return item stack representing icon */ public ItemStack getIcon() { return this.icon; } }
3,435
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
KitInventoryMenu.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/kits/KitInventoryMenu.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.kits; import java.util.ArrayList; import java.util.List; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.actions.JavaArbitraryAction; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenu; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenuItem; import eu.matejkormuth.pexel.PexelCore.util.ParametrizedRunnable; /** * Class representating inventory menu for kits. * * @author Mato Kormuth * */ public class KitInventoryMenu { private final InventoryMenu menu; private ParametrizedRunnable onKitSelected; /** * Creates a new inventory menu for selecting kit. * * @param kits * kits in inventory menu. */ public KitInventoryMenu(final Kit... kits) { List<InventoryMenuItem> items = new ArrayList<InventoryMenuItem>(); for (int i = 0; i < kits.length; i++) { final Kit kit = kits[i]; items.add(new InventoryMenuItem(kit.getIcon(), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { kit.applyKit(((Player) args[0])); KitInventoryMenu.this.onKitSelected.run(args[0], kit); } }), i, false)); } this.menu = new InventoryMenu(9, "Select kit: ", items); } public void setOnKitSelected(final ParametrizedRunnable runnable) { this.onKitSelected = runnable; } /** * Shows inventory to player. * * @param player * player to show menu to */ public void showTo(final Player player) { this.menu.showTo(player); } }
2,641
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
StorageEngine.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/StorageEngine.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.bukkit.Location; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.player.PlayerQuitEvent; import eu.matejkormuth.pexel.PexelCore.PexelCore; import eu.matejkormuth.pexel.PexelCore.areas.AreaFlag; import eu.matejkormuth.pexel.PexelCore.areas.Lobby; import eu.matejkormuth.pexel.PexelCore.areas.ProtectedArea; import eu.matejkormuth.pexel.PexelCore.arenas.AbstractArena; import eu.matejkormuth.pexel.PexelCore.arenas.ArenaOption; import eu.matejkormuth.pexel.PexelCore.arenas.DisconnectReason; import eu.matejkormuth.pexel.PexelCore.arenas.MapData; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * All data of plugin is stored in this class. * * @author Mato Kormuth * */ @SuppressWarnings("deprecation") // SuppressWarning - Because of ArenaOption. public class StorageEngine { private static final Map<UUID, PlayerProfile> profiles = new HashMap<UUID, PlayerProfile>(); private static final Map<String, Minigame> minigames = new HashMap<String, Minigame>(); private static final Map<String, ProtectedArea> areas = new HashMap<String, ProtectedArea>(); private static final Map<String, AbstractArena> arenas = new HashMap<String, AbstractArena>(); private static final Map<String, Class<?>> aliases = new HashMap<String, Class<?>>(); private static final Map<String, Lobby> lobbies = new HashMap<String, Lobby>(); private static final Map<String, TeleportGate> gates = new HashMap<String, TeleportGate>(); private static boolean initialized = false; /** * Initializes static obeject of storage engine. * * @param core * pexel core */ public static void initialize(final PexelCore core) { if (!StorageEngine.initialized) StorageEngine.initialized = true; } /** * Returns UUIDs of player's friends. * * @param player * player * @return lsit of friends */ public static List<UUID> getFriends(final Player player) { return StorageEngine.profiles.get(player.getUniqueId()).getFriends(); } /** * Returns UUIDs of player's foes. * * @param player * @return */ public static List<UUID> getFoes(final Player player) { return StorageEngine.profiles.get(player.getUniqueId()).getFoes(); } /** * Returns map of areas. * * @return */ public static Map<String, ProtectedArea> getAreas() { return StorageEngine.areas; } /** * Returns profile of specified player. * * @param player * @return */ public static PlayerProfile getProfile(final UUID player) { return profiles.get(player); } /** * Returns minigame by its name. * * @param name * name of minigame * @return minigame object */ public static Minigame getMinigame(final String name) { return StorageEngine.minigames.get(name); } /** * Registers minigame. * * @param minigame */ public static void addMinigame(final Minigame minigame) { StorageEngine.minigames.put(minigame.getName(), minigame); } /** * Registers mingiame's arena. * * @param arena */ public static void addArena(final AbstractArena arena) { StorageEngine.arenas.put(arena.getName(), arena); StorageEngine.areas.put(arena.getName(), arena); } /** * Returns minigame arenas count. * * @return count of minigame arenas. */ public static int getMinigameArenasCount() { return StorageEngine.arenas.size(); } /** * Returns count of mingiame. * * @return count of minigame */ public static int getMinigamesCount() { return StorageEngine.minigames.size(); } protected static Map<String, Minigame> getMinigames() { return StorageEngine.minigames; } public static Map<String, AbstractArena> getArenas() { return StorageEngine.arenas; } public static AbstractArena getArena(final String arenaName) { return StorageEngine.arenas.get(arenaName); } public static void addGate(final String name, final TeleportGate gate) { StorageEngine.gates.put(name, gate); } public static TeleportGate getGate(final String name) { return StorageEngine.gates.get(name); } public static void removeGate(final String name) { StorageEngine.gates.remove(name); } @SuppressWarnings("rawtypes") public static void registerArenaAlias(final Class arenaClass, final String alias) { StorageEngine.aliases.put(alias, arenaClass); } @SuppressWarnings("rawtypes") public static Class getByAlias(final String alias) { return StorageEngine.aliases.get(alias); } public static Map<String, Class<?>> getAliases() { return StorageEngine.aliases; } public static void addLobby(final Lobby lobby) { StorageEngine.lobbies.put(lobby.getName(), lobby); StorageEngine.areas.put(lobby.getName(), lobby); } public static Lobby getLobby(final String lobbyName) { return StorageEngine.lobbies.get(lobbyName); } /** * Saves player's profile to file. * * @param uniqueId */ public static void saveProfile(final UUID uniqueId) { Log.info("Saving profile for " + uniqueId.toString() + " to disk..."); StorageEngine.profiles.get(uniqueId).save(Paths.playerProfile(uniqueId)); } /** * Loads player profile from disk or creates an empty one. * * @param uniqueId */ public static void loadProfile(final UUID uniqueId) { File f = new File(Paths.playerProfile(uniqueId)); if (f.exists()) { Log.info("Load profile for " + uniqueId + "..."); StorageEngine.profiles.put(uniqueId, PlayerProfile.load(Paths.playerProfile(uniqueId))); } else { Log.info("Creating new profile for " + uniqueId.toString()); StorageEngine.profiles.put(uniqueId, new PlayerProfile(uniqueId)); } } /** * @deprecated deprecated and WILL be removed in future. Use {@link MapData}. */ @Deprecated public static void saveData() { Log.info("Saving data..."); // Save lobbies. YamlConfiguration yaml_lobbies = new YamlConfiguration(); int i_lobbies = 0; for (Lobby l : StorageEngine.lobbies.values()) { yaml_lobbies.set("lobbies.lobby" + i_lobbies + ".name", l.getName()); yaml_lobbies.set("lobbies.lobby" + i_lobbies + ".checkinterval", l.getCheckInterval()); // Save global flags for (AreaFlag flag : AreaFlag.values()) if (l.getGlobalFlag(flag) != ProtectedArea.defaultFlags.get(flag)) yaml_lobbies.set( "lobbies.lobby" + i_lobbies + ".gflags." + flag.toString(), l.getGlobalFlag(flag)); yaml_lobbies.set("lobbies.lobby" + i_lobbies + ".thresholdY", l.getThresholdY()); l.getRegion().serialize(yaml_lobbies, "lobbies.lobby" + i_lobbies + ".region"); i_lobbies++; } try { yaml_lobbies.save(new File(Paths.lobbiesPath())); Log.info("Saved " + i_lobbies + " lobbies!"); } catch (IOException e) { e.printStackTrace(); } // Save arenas YamlConfiguration yaml_arenas = new YamlConfiguration(); int i_arenas = 0; for (AbstractArena a : StorageEngine.arenas.values()) { yaml_arenas.set("arenas.arena" + i_arenas + ".name", a.getName()); yaml_arenas.set("arenas.arena" + i_arenas + ".type", a.getClass().getSimpleName()); yaml_arenas.set("arenas.arena" + i_arenas + ".minigame", a.getMinigame().getName()); yaml_arenas.set("arenas.arena" + i_arenas + ".slots", a.getMaximumSlots()); // Get options for (Field f : a.getClass().getDeclaredFields()) if (f.isAnnotationPresent(ArenaOption.class)) { if (!f.isAccessible()) f.setAccessible(true); try { if (f.get(a) != null) { yaml_arenas.set( "arenas.arena" + i_arenas + ".options." + f.getName(), f.get(a).toString()); } } catch (IllegalArgumentException | IllegalAccessException e) { System.out.println("Error while saving arena " + a.getName() + "!"); e.printStackTrace(); } } // Save global flags for (AreaFlag flag : AreaFlag.values()) if (a.getGlobalFlag(flag) != ProtectedArea.defaultFlags.get(flag)) yaml_arenas.set( "arenas.arena" + i_arenas + ".gflags." + flag.toString(), a.getGlobalFlag(flag)); yaml_arenas.set("arenas.arena" + i_arenas + ".owner", a.getOwner()); if (a.getRegion() != null) a.getRegion().serialize(yaml_arenas, "arenas.arena" + i_arenas + ".region"); i_arenas++; } try { yaml_arenas.save(new File(Paths.arenasPath())); Log.info("Saved " + i_arenas + " arenas!"); } catch (IOException e) { e.printStackTrace(); } // Save gates YamlConfiguration yaml_gates = new YamlConfiguration(); int i_gates = 0; for (String key : StorageEngine.gates.keySet()) { TeleportGate tg = StorageEngine.gates.get(key); yaml_gates.set("gates.gate" + i_gates + ".name", key); yaml_gates.set("gates.gate" + i_gates + ".action.type", tg.getAction().getClass().getSimpleName()); if (tg.getRegion() != null) tg.getRegion().serialize(yaml_gates, "gates.gate" + i_gates + ".region"); i_gates++; } try { yaml_gates.save(new File(Paths.gatesPath())); Log.info("Saved " + i_gates + " gates!"); } catch (IOException e) { e.printStackTrace(); } } public static void loadData() { Log.info("Loading data..."); } public static void gateEnter(final Player player, final Location location) { // Find the right gate for (TeleportGate gate : StorageEngine.gates.values()) if (gate.getRegion().intersects(location)) gate.teleport(player); } public static void saveArenas() { for (AbstractArena arena : StorageEngine.arenas.values()) { // Will be removed. arena.save(Paths.arenaPath(arena.getBannableName())); } } public static void saveProfiles() { for (PlayerProfile profile : StorageEngine.profiles.values()) { profile.saveXML(Paths.profilePath(profile.getUniqueId().toString())); } } public static void __redirectEvent(final String string, final Event event) { if (string.equalsIgnoreCase("PlayerQuitEvent")) { PlayerQuitEvent quitevent = (PlayerQuitEvent) event; for (AbstractArena arena : StorageEngine.arenas.values()) { if (arena.contains(quitevent.getPlayer())) { arena.onPlayerLeft(quitevent.getPlayer(), DisconnectReason.PLAYER_DISCONNECT); } } } } }
13,337
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Auth.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Auth.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; /** * Class used for offline mode authentication. */ public class Auth { public void authenticateCommand(final Player player, final String password) { // TODO: PHP or MYSQL Implementation to integrate with unified login system. // Unfreeze player. Pexel.getPlayerFreezer().unfreeze(player); player.sendMessage(ChatManager.success("Successfully logged in!")); } public void authenticateIp(final Player player, final String hostname) { // TODO: PHP or MYSQL Implementation to integrate with unified login system. } }
1,608
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Region.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Region.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlTransient; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import com.sk89q.worldedit.bukkit.selections.Selection; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.util.SerializableVector; /** * Class used for regions. * * @author Mato Kormuth * */ @XmlAccessorType(XmlAccessType.FIELD) public class Region { /** * First vector. */ @XmlElement(name = "vector1") protected final SerializableVector v1; /** * Second vector. */ @XmlElement(name = "vector2") protected final SerializableVector v2; /** * World of region. */ @XmlTransient protected final World w; @XmlElement(name = "world") protected final String w_name; /** * Creates a new region from two locations. * * @param loc1 * first location * @param loc2 * second location */ public Region(final Location loc1, final Location loc2) { this.v1 = new SerializableVector(loc1.toVector()); this.v2 = new SerializableVector(loc2.toVector()); this.w = loc1.getWorld(); this.w_name = loc1.getWorld().getName(); } /** * Creates a new region from two vectors and one world. Similar to {@link Region#Region(Location, Location)} * * @param v1 * minimum point * @param v2 * maximum point * @param w * world */ public Region(final Vector v1, final Vector v2, final World w) { this.v1 = new SerializableVector(v1); this.v2 = new SerializableVector(v2); this.w = w; this.w_name = w.getName(); } /** * Creates a new region with center and size. * * @param center * center * @param w * world * @param size * size */ public Region(final Vector center, final World w, final int size) { this.v1 = new SerializableVector( center.clone().add(new Vector(size, size, size))); this.v2 = new SerializableVector(center.clone().add( new Vector(-size, -size, -size))); this.w = w; this.w_name = w.getName(); } /** * Creates a new region from WorldEdit selection. * * @param selection * worldedit selection */ public Region(final Selection selection) { this.v1 = new SerializableVector(selection.getMinimumPoint().toVector()); this.v2 = new SerializableVector(selection.getMaximumPoint().toVector()); this.w = selection.getWorld(); this.w_name = this.w.getName(); } /** * Returns whether the location intersect the region. * * @param loc * location to check. * @return */ public boolean intersects(final Location loc) { if (this.w.getName().equals(loc.getWorld().getName())) return this.intersects(loc.toVector()); else return false; } /** * Returns whether the location intersects X and Z coordinate of this region. * * @param loc * location to check * @return */ public boolean intersectsXZ(final Location loc) { if (this.w.getName().equals(loc.getWorld().getName())) return this.intersectsXZ(loc.toVector()); else return false; } /** * Returns whatever vector intersects the region. * * @param v * vector to check * @return */ public boolean intersects(final Vector v) { return Region.range(this.v1.getX(), this.v2.getX(), v.getX()) && Region.range(this.v1.getY(), this.v2.getY(), v.getY()) && Region.range(this.v1.getZ(), this.v2.getZ(), v.getZ()); } public boolean intersectsXZ(final Vector v) { return Region.range(this.v1.getX(), this.v2.getX(), v.getX()) && Region.range(this.v1.getZ(), this.v2.getZ(), v.getZ()); } /** * Returns players in region. * * @return list of players */ public List<Player> getPlayersXYZ() { List<Player> players = new ArrayList<Player>(); for (Player player : Bukkit.getOnlinePlayers()) if (this.intersects(player.getLocation())) players.add(player); return players; } public void serialize(final YamlConfiguration yaml, final String string) { yaml.set(string + ".v1.x", this.v1.getBlockX()); yaml.set(string + ".v1.y", this.v1.getBlockY()); yaml.set(string + ".v1.z", this.v1.getBlockZ()); yaml.set(string + ".v2.x", this.v2.getBlockX()); yaml.set(string + ".v2.y", this.v2.getBlockY()); yaml.set(string + ".v2.z", this.v2.getBlockZ()); yaml.set(string + ".world", this.w.getName()); } private final static boolean range(final double min, final double max, final double value) { if (max > min) return (value <= max ? (value >= min ? true : false) : false); else return (value <= min ? (value >= max ? true : false) : false); } /** * Retruns first vector. * * @return vector */ public Location getV1Loaction() { return new Location(this.w, this.v1.getX(), this.v1.getY(), this.v1.getZ()); } /** * Returns second vector. * * @return vector */ public Location getV2Location() { return new Location(this.w, this.v2.getX(), this.v2.getY(), this.v2.getZ()); } @Override public String toString() { return "Region{x1:" + this.v1.getBlockX() + ",y1:" + this.v1.getBlockY() + ",z1:" + this.v1.getBlockZ() + ",x2:" + this.v2.getBlockX() + ",y2:" + this.v2.getBlockY() + ",z2:" + this.v2.getBlockZ() + ",world:" + this.w.getName() + "}"; } /** * Returns players in XZ region. * * @return list of players. */ public List<Player> getPlayersXZ() { List<Player> players = new ArrayList<Player>(); for (Player player : Bukkit.getOnlinePlayers()) if (this.intersectsXZ(player.getLocation())) players.add(player); return players; } public double getMaxX() { if (this.v1.getX() > this.v2.getX()) return this.v1.getX(); else return this.v2.getX(); } public double getMaxY() { if (this.v1.getY() > this.v2.getY()) return this.v1.getY(); else return this.v2.getY(); } public double getMaxZ() { if (this.v1.getZ() > this.v2.getZ()) return this.v1.getZ(); else return this.v2.getZ(); } public double getMinX() { if (this.v1.getX() > this.v2.getX()) return this.v2.getX(); else return this.v1.getX(); } public double getMinY() { if (this.v1.getY() > this.v2.getY()) return this.v2.getY(); else return this.v1.getY(); } public double getMinZ() { if (this.v1.getZ() > this.v2.getZ()) return this.v2.getZ(); else return this.v1.getZ(); } public World getWorld() { return this.w; } /** * Returns random location from this region. * * @return random location in bounds of this region */ public Location getRandomLocation() { int a = this.rnd((int) (this.getMaxX() - this.getMinX())); int b = this.rnd((int) (this.getMaxY() - this.getMinY())); int c = this.rnd((int) (this.getMaxZ() - this.getMinZ())); return new Location(this.w, this.getMinX() + a, this.getMinY() + b, this.getMinZ() + c); } private int rnd(final int max) { if (max == 0) { return 0; } else { return Pexel.getRandom().nextInt(max); } } /** * Returns list of blocks in this region. <b>Notice: can be slow on big regions.</b> * * @return list of region's blocks */ public List<Block> getBlocks() { List<Block> blocks = new ArrayList<Block>(500); int maxX = (int) this.getMaxX(); int maxY = (int) this.getMaxY(); int maxZ = (int) this.getMaxZ(); for (int x = (int) this.getMinX(); x <= maxX; x++) { for (int y = (int) this.getMinY(); y <= maxY; y++) { for (int z = (int) this.getMinZ(); z <= maxZ; z++) { blocks.add(this.w.getBlockAt(x, y, z)); } } } return blocks; } /** * Creates region around specified location with specified size. * * @param center * center * @param size * size * @return region */ public static Region createAroundBox(final Location center, final int size) { return new Region(center.toVector().add(new Vector(size, size, size)), center.toVector().subtract(new Vector(size, size, size)), center.getWorld()); } /** * @return */ public double getWidth() { return this.getMaxX() - this.getMinX(); } public double getHeight() { return this.getMaxY() - this.getMinY(); } public double getLength() { return this.getMaxZ() - this.getMinZ(); } }
10,966
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Achievements.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Achievements.java
package eu.matejkormuth.pexel.PexelCore.core; import java.util.HashMap; import java.util.Map; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Represents achievements over network. */ public class Achievements { private final Map<String, Achievement> achievements = new HashMap<String, Achievement>(); /** * Registers achievement in pexel to enable its synchronization over network. * * @see Achievement#minigame(Minigame, String, String) * @see Achievement#global(String, String) * * @param achievement * achievement to register. */ public void registerAchievement(final Achievement achievement) { Log.info("Registering achievement '" + achievement.getDisplayName() + "'..."); this.achievements.put(achievement.getName(), achievement); } /** * Returns achievement by name or null if achievement for specified name not found. * * @param name * achievement name * @return achievement object or null if not found */ public Achievement getAchievement(final String name) { return this.achievements.get(name); } /** * Set's progress to specified value. * * @param progress * new progress * @throws IllegalArgumentException * when progress is bigger the max progress */ public void setProgress(final Achievement achievement, final Player player, final int progress) { if (progress <= achievement.getMaxProgress()) { this.update(achievement, player, progress); } else { throw new IllegalArgumentException("progress is smalled the maxProgress"); } } /** * Returns the current progress of achievement. * * @return the current progress */ public int getProgress(final Achievement achievement, final Player player) { return this.getState(achievement, player); } /** * Sets player status of this achievement to 'achieved' (achievement progress to max progress value - * {@link Achievement#getMaxProgress()}). * * @param achievement * achievement to unlock * @param player * player */ public void achieve(final Achievement achievement, final Player player) { this.update(achievement, player, achievement.getMaxProgress()); } /** * Returns whether the specified player has achieved specififed achievement (progress equals to achievement's max * progress - {@link Achievement#getMaxProgress()}). * * @param achievement * achievement to check * @param player * player to check * @return true or false */ public boolean hasAchieved(final Achievement achievement, final Player player) { return this.getState(achievement, player) == achievement.getMaxProgress(); } private int getState(final Achievement achievement, final Player player) { // TODO Auto-generated method stub return 0; } private void update(final Achievement achievement, final Player player, final int maxProgress) { // TODO Auto-generated method stub } }
3,348
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Economics.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Economics.java
package eu.matejkormuth.pexel.PexelCore.core; import org.bukkit.entity.Player; /** * */ public class Economics { public void addCoins(final Player player, final int amount) { StorageEngine.getProfile(player.getUniqueId()).addPoints(amount); } }
265
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
License.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/License.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; /** * Class that has only one purpose - print license. */ public final class License { public static final void print() { System.out.println("==================================================================="); System.out.println(" Pexel Project - Minecraft minigame server platform. "); System.out.println(" Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu>"); System.out.println(""); System.out.println(" Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as"); System.out.println(" published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version."); System.out.println(""); System.out.println(" Pexel is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty"); System.out.println(" of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details."); System.out.println(""); System.out.println(" You should have received a copy of the GNU General Public License along with this program. If not, see"); System.out.println(" <http://www.gnu.org/licenses/>."); System.out.println("==================================================================="); } }
2,267
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Party.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Party.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.matchmaking.MatchmakingGame; import eu.matejkormuth.pexel.PexelCore.matchmaking.MatchmakingRequest; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Class used for party. * * @author Mato Kormuth * */ public class Party implements PlayerHolder { private final List<Player> players; private final Player owner; /** * Creates new party. * * @param owner * owner of the party */ public Party(final Player owner) { this.players = new ArrayList<Player>(); this.owner = owner; owner.sendMessage(ChatManager.success("Created new party!")); } /** * Returns whether is specified player owner of the party. * * @param player * specified player * @return true or false */ public boolean isOwner(final Player player) { return this.owner == player; } /** * Adds player to party. * * @param player * player to be added */ public void addPlayer(final Player player) { this.players.add(player); player.sendMessage(ChatManager.success("You have joined " + this.owner.getDisplayName() + "'s party!")); } /** * Makes {@link MatchmakingRequest} from this party. * * @param minigame * specified minigame * @param game * specified arena * @return request */ public MatchmakingRequest toRequest(final Minigame minigame, final MatchmakingGame game) { return new MatchmakingRequest(this.players, minigame, game); } @Override public Collection<Player> getPlayers() { return this.players; } @Override public int getPlayerCount() { return this.players.size(); } public void removePlayer(final Player player) { this.players.remove(player); StorageEngine.getProfile(player.getUniqueId()).setParty(null); } @Override public boolean contains(final Player player) { return this.players.contains(player); } }
3,239
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
AutoMessage.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/AutoMessage.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.List; import java.util.Random; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * AutoMessage. * */ public class AutoMessage implements Updatable { private static final List<String> strings = new ArrayList<String>(); private static final String prefix = ""; private static final long interval = 20000 / 30; //each 60 seconds. private static final Random random = new Random(); private static int taskId = 0; private static boolean enabled = false; static { AutoMessage.strings.add("Hras " + ChatColor.BLUE + "BETA" + ChatColor.RESET + " verziu pexel-u. Dakujeme!"); AutoMessage.strings.add("Navstivte aj nasu web stranku www.pexel.eu (v priprave)!"); AutoMessage.strings.add("Hras " + ChatColor.BLUE + "BETA" + ChatColor.RESET + " verziu pexel-u. Dakujeme!"); AutoMessage.strings.add("Ak mas nejake pripomienky, povedz nam na " + ChatColor.GREEN + "ts.mertex.eu!"); } /** * Boradcast random message to chat. */ public static void pushMessage() { Bukkit.broadcastMessage(AutoMessage.prefix + AutoMessage.strings.get(AutoMessage.random.nextInt(AutoMessage.strings.size()))); } /** * Returns if is AutoMessage enabled. * * @return true or false */ public static boolean isEnabled() { return AutoMessage.enabled; } @Override public void updateStart() { Log.partEnable("Automessage"); UpdatedParts.registerPart(this); AutoMessage.enabled = true; AutoMessage.taskId = Pexel.getScheduler().scheduleSyncRepeatingTask( new Runnable() { @Override public void run() { AutoMessage.pushMessage(); } }, 0, AutoMessage.interval); } @Override public void updateStop() { Log.partDisable("Automessage"); AutoMessage.enabled = false; Pexel.getScheduler().cancelTask(AutoMessage.taskId); } }
3,213
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Achievement.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Achievement.java
package eu.matejkormuth.pexel.PexelCore.core; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Class that represents achievement. */ public class Achievement { private String name; private String displayName; private String description; private int maxProgress; /** * Private constructor. Please use static methods. */ private Achievement() { } /** * Builds achievement for specified minigame with specified name and display name. * * @param minigame * minigame * @param name * name of achievement (will be automatically prefixed with '{minigamename}.'). * @param description * description of achievement * @param displayName * display name * @param maxProgress * maximum progress of achievement * @return achievement */ public static Achievement minigame(final Minigame minigame, final String name, final String description, final String displayName, final int maxProgress) { Achievement ach = new Achievement(); ach.name = minigame.getName() + "." + name; ach.displayName = displayName; ach.description = description; ach.maxProgress = maxProgress; return ach; } /** * Builds global achievement that applies to whole network with specified name and display name. * * @param name * name (will be automatically prefixed with 'global.'). * @param displayName * display name * @param description * description of achievement * @param maxProgress * maximum progress of achievement * @return achievement */ public static Achievement global(final String name, final String displayName, final String description, final int maxProgress) { Achievement ach = new Achievement(); ach.name = "global." + name; ach.displayName = displayName; ach.description = description; ach.maxProgress = maxProgress; return ach; } /** * Returns the name of achievement. * * @return the name */ public String getName() { return this.name; } /** * Returns the description. * * @return the description */ public String getDescription() { return this.description; } /** * Returns the max progress value of this achievement (<b>value, when achievement is awarded to player<b>). * * @return the max progress value */ public int getMaxProgress() { return this.maxProgress; } /** * Returns the display name of achievement. * * @return the display name of achievement */ public String getDisplayName() { return this.displayName; } }
2,941
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
UpdatedParts.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/UpdatedParts.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.List; /** * Class that turns off all parts when needed. Idk what is this... * * @author Mato Kormuth * */ public class UpdatedParts { private static List<Updatable> parts = new ArrayList<Updatable>(); public static void shutdown() { for (Updatable part : UpdatedParts.parts) part.updateStop(); UpdatedParts.parts.clear(); } public static void registerPart(final Updatable part) { Log.info("[UpdatedParts] Registering: " + part.getClass().getSimpleName()); UpdatedParts.parts.add(part); } }
1,489
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PlayerHolder.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/PlayerHolder.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.Collection; import org.bukkit.entity.Player; /** * Specifies class that hold collection of players. * * @author Mato Kormuth * */ public interface PlayerHolder { /** * Returns collection of players in this object. * * @return list of players. */ public Collection<Player> getPlayers(); /** * Returns number of players in this object. * * @return player count */ public int getPlayerCount(); /** * Returns whether object contains specified player. * * @param player * specified player to check * @return whether the object contains player or not */ public boolean contains(Player player); }
1,606
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
TeleportGate.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/TeleportGate.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.actions.Action; /** * Class representating teleport portal. * * @author Mato Kormuth * */ public class TeleportGate { private final Region region; private Action action; /** * Creates new teleport gate in specified region, with specified action that will be executed when PlayerPortalEvent * is thrown for this gate. * * @param region * region of gate * @param action * action to be executed */ public TeleportGate(final Region region, final Action action) { this.region = region; this.action = action; } /** * Retruns region of gate. * * @return */ public Region getRegion() { return this.region; } /** * Executes specified action on specified player. * * @param player * player to execute action to */ protected void teleport(final Player player) { this.action.execute(player); } /** * Returns action of this gate. * * @return action */ public Action getAction() { return this.action; } /** * Sets action to this teleport gate. * * @param action * action */ public void setAction(final Action action) { this.action = action; } }
2,310
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Paths.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Paths.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.UUID; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * Class used for generating paths. * * @author Mato Kormuth * */ public class Paths { /** * Returns path for player profile. * * @param uuid * @return */ public static final String playerProfile(final UUID uuid) { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/profiles/" + uuid.toString() + ".yml"; } public static String lobbiesPath() { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/lobbies.yml"; } public static String arenasPath() { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/arenas.yml"; } public static String gatesPath() { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/gates.yml"; } public static String msuCache() { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/msu.cache"; } public static String matchRecord(final String name) { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/records/" + name + ".record"; } public static String arenaPath(final String name) { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/arenas/" + name + ".xml"; } public static String profilePath(final String name) { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/profiles/" + name + ".xml"; } public static String cache(final String name) { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/cache/" + name + ".cache"; } public static String clips() { return Pexel.getCore().getDataFolder().getAbsolutePath() + "/clips/"; } }
2,706
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ValidityChecker.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/ValidityChecker.java
package eu.matejkormuth.pexel.PexelCore.core; import org.apache.commons.lang.StringUtils; import eu.matejkormuth.pexel.PexelCore.arenas.MapData; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Class that is used for checking validity of parts registered to pexel. */ public final class ValidityChecker { public static void checkMinigame(final Minigame minigame) { if (!minigame.getName().matches("^[a-z0-9]*$")) { throw new ValidationException( "Minigame name does not match pattern '[a-zA-Z0-9]'!"); } if (minigame.getCategory() == null) { throw new ValidationException( "Minigame must return category!"); } } public static void checkMapData(final MapData mapData) { if (StringUtils.isBlank(mapData.getAuthor())) { throw new ValidationException( "Map author can't be blank!"); } if (StringUtils.isBlank(mapData.getName())) { throw new ValidationException( "Map name can't be blank!"); } if (mapData.getMaxPlayers() < 1) { System.out.println("Max players should probably be more than one!"); } if (mapData.getProtectedRegion() == null) { throw new ValidationException( "Protected region can't be null!"); } if (mapData.getWorld() == null) { throw new ValidationException( "World not found on server!"); } } public static class ValidationException extends RuntimeException { private static final long serialVersionUID = 8219849002256286968L; public ValidationException(final String s) { super(s); } } }
1,674
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
MagicClock.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/MagicClock.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.Arrays; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.actions.CommandAction; import eu.matejkormuth.pexel.PexelCore.actions.JavaArbitraryAction; import eu.matejkormuth.pexel.PexelCore.actions.TeleportAction; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenu; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenuItem; import eu.matejkormuth.pexel.PexelCore.util.ItemUtils; import eu.matejkormuth.pexel.PexelCore.util.ParametrizedRunnable; /** * Class used for MagicClock. * * @auhtor Mato Kormuth * */ public class MagicClock implements Listener { private InventoryMenu iventoryMenu; public void buildInventoryMenu() { InventoryMenuItem everybodyItem = new InventoryMenuItem( ItemUtils.namedItemStack(Material.EYE_OF_ENDER, "Everybody", null), new JavaArbitraryAction(new ParametrizedRunnable() { @Override public void run(final Object... args) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { ((Player) args[0]).showPlayer(onlinePlayer); } ((Player) args[0]).sendMessage(ChatManager.success("Now you can see everybody!")); } }), 0, true); InventoryMenuItem nobodyItem = new InventoryMenuItem(ItemUtils.namedItemStack( Material.ENDER_PEARL, "Nobody", null), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { //if (StorageEngine.getProfile( // ((Player) args[0]).getUniqueId()).isFriend( // onlinePlayer.getUniqueId())) // ((Player) args[0]).showPlayer(onlinePlayer); //else ((Player) args[0]).hidePlayer(onlinePlayer); } ((Player) args[0]).sendMessage(ChatManager.success("All players have been vanished!")); } }), 1, true); //InventoryMenuItem kickItem = new InventoryMenuItem(ItemUtils.namedItemStack( // Material.APPLE, "Kick me", null), new KickAction(), 2, true); InventoryMenuItem teleportItem = new InventoryMenuItem(ItemUtils.namedItemStack( Material.BED, "Teleport to 0 255 0", null), new TeleportAction( new Location(Bukkit.getWorld("world"), 0, 255, 0)), 3, true); InventoryMenuItem commandItem = new InventoryMenuItem(ItemUtils.namedItemStack( Material.BEACON, "Suprise", null), new CommandAction("me je gay"), 4, false); InventoryMenuItem soundItem = new InventoryMenuItem(ItemUtils.namedItemStack( Material.NOTE_BLOCK, "Sound", null), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { ((Player) args[0]).playSound(((Player) args[0]).getLocation(), Sound.ZOMBIE_REMEDY, 1, 1); ((Player) args[0]).playSound(((Player) args[0]).getLocation(), Sound.AMBIENCE_CAVE, 1, 1); ((Player) args[0]).playSound(((Player) args[0]).getLocation(), Sound.ZOMBIE_METAL, 1, 1); ((Player) args[0]).playSound(((Player) args[0]).getLocation(), Sound.BURP, 1, 1); } }), 5, false); this.iventoryMenu = new InventoryMenu(InventoryType.CHEST, "Player visibility", Arrays.asList(everybodyItem, nobodyItem, teleportItem, commandItem, soundItem)); } public MagicClock() { Bukkit.getPluginManager().registerEvents(this, Pexel.getCore()); this.buildInventoryMenu(); } @EventHandler private void onPlayerInteract(final PlayerInteractEvent event) { if (event.getPlayer().getItemInHand() != null) if (event.getPlayer().getItemInHand().getType() == Material.WATCH) this.iventoryMenu.showTo(event.getPlayer()); /* * if (event.getPlayer().getItemInHand() != null) if (event.getPlayer().getItemInHand().getType() == * Material.WATCH) { ItemMeta meta = event.getPlayer().getItemInHand().getItemMeta(); String rezim = * meta.getLore().get(0).substring(7); * * if (rezim.equalsIgnoreCase("Vsetci")) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { * event.getPlayer().showPlayer(onlinePlayer); } * * meta.setLore(Arrays.asList("Rezim: Priatelia", "Pouzi a skry/zobraz skaredych hracov.")); } else if * (rezim.equalsIgnoreCase("Priatelia")) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { if * (StorageEngine.getProfile( event.getPlayer().getUniqueId()).isFriend( onlinePlayer.getUniqueId())) * event.getPlayer().showPlayer(onlinePlayer); else event.getPlayer().hidePlayer(onlinePlayer); } * * meta.setLore(Arrays.asList("Rezim: Nikto", "Pouzi a skry/zobraz skaredych hracov.")); } else if * (rezim.equalsIgnoreCase("Nikto")) { for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { * event.getPlayer().hidePlayer(onlinePlayer); } * * meta.setLore(Arrays.asList("Rezim: Vsetci", "Pouzi a skry/zobraz skaredych hracov.")); } * * event.getPlayer().getItemInHand().setItemMeta(meta); } */ } public ItemStack getClock() { ItemStack itemstack = new ItemStack(Material.WATCH); ItemMeta meta = itemstack.getItemMeta(); meta.setDisplayName(ChatColor.GOLD + "Magic Cock"); meta.setLore(Arrays.asList("Rezim: Vsetci", "Pouzi a skry/zobraz skaredych hracov.")); itemstack.setItemMeta(meta); return itemstack; } }
7,693
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
RegionTransformer.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/RegionTransformer.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import org.bukkit.Location; public class RegionTransformer { /** * Transforms relative region to absolute with specified anchor. * * @param relative * relative region * @param anchor * absolute anchor * @return absoluted region */ public static Region toAbsolute(final Region relative, final Location anchor) { return new Region(anchor.toVector().add(relative.v1), anchor.toVector().add( relative.v2), anchor.getWorld()); } }
1,408
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Updatable.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Updatable.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; /** * Interface that suggests that this call is updatable. */ public interface Updatable { /** * Called when part should start it's update logic. */ void updateStart(); /** * Called when part should stop it's update logic. */ void updateStop(); }
1,162
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Log.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Log.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; /** * Logger for pexel. * * @author Mato Kormuth * */ public class Log { /** * List of problems, that should admins able to view. */ private final static List<String> problems = new ArrayList<String>(); /** * Internal logger. */ private final static Logger log = Logger.getLogger("PexelCore"); /** * Logs 'info' message. * * @param msg * message to log */ public final static void info(final String msg) { Log.log.info("[PEXEL] " + msg); ChatManager.CHANNEL_LOG.broadcastMessage(ChatColor.GRAY + "[INFO] " + msg); } /** * Logs 'warn' message. * * @param msg * message to log */ public final static void warn(final String msg) { Log.log.warning("[PEXEL] " + msg); ChatManager.CHANNEL_LOG.broadcastMessage(ChatColor.GOLD + "[WARN] " + msg); } /** * Logs 'severe' message. * * @param msg * message to log */ public final static void severe(final String msg) { Log.log.severe("[PEXEL] " + msg); ChatManager.CHANNEL_LOG.broadcastMessage(ChatColor.RED + "[ERROR] " + msg); } /** * Logs 'partEnable' message. * * @param partName * message to log */ public final static void partEnable(final String partName) { Log.log.info("[PEXEL] " + "Enabling Pexel-" + partName + "..."); ChatManager.CHANNEL_LOG.broadcastMessage(ChatColor.GRAY + "[PARTENABLE] " + partName); } /** * Logs 'parnDisable' message. * * @param partName * message to log */ public final static void partDisable(final String partName) { Log.log.info("[PEXEL] " + "Disabling Pexel-" + partName + "..."); ChatManager.CHANNEL_LOG.broadcastMessage(ChatColor.GRAY + "[PARTDISABLE] " + partName); } /** * Logs 'gameEnable' message. * * @param gameName * message to log */ public final static void gameEnable(final String gameName) { Log.log.info("[PEXEL] " + "Enabling Minigame-" + gameName + "..."); } /** * Logs 'gameDisable' message. * * @param gameName * message to log */ public final static void gameDisable(final String gameName) { Log.log.info("[PEXEL] " + "Disabling Minigame-" + gameName + "..."); } /** * Adds problem to list. Problem is added to log and reported to all OP on server. * * @param message */ public final static void addProblem(final String message) { Log.problems.add(message); for (Player p : Bukkit.getOnlinePlayers()) if (p.isOp()) p.sendMessage(ChatColor.RED + "[Problem]" + message); } /** * Returns list of all problems. * * @return list of problems */ protected final static List<String> getProblems() { return Log.problems; } public static void chat(final String msg) { Log.log.info("[CHAT] " + msg); } private static void prblm_rpt_msg() { for (String message : Log.getProblems()) for (Player p : Bukkit.getOnlinePlayers()) if (p.isOp()) p.sendMessage(ChatColor.RED + "[Problem]" + message); } public static void ___prblm_stp() { Pexel.getScheduler().scheduleSyncDelayedTask(new Runnable() { @Override public void run() { Log.prblm_rpt_msg(); } }, 200L); } }
4,868
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Scheduler.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Scheduler.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * Scheduler class for pexel to be used when porting from Bukkit to Sponge.. */ public class Scheduler { private final List<ScheduledTask> tasks = new ArrayList<ScheduledTask>(); private long elapsed; private ArrayList<ScheduledTask> temptasks; public Scheduler() { Log.partEnable("Scheduler"); Bukkit.getScheduler().scheduleSyncRepeatingTask(Pexel.getCore(), new Runnable() { @Override public void run() { Scheduler.this.tick(); } }, 1L, 0L); } public int scheduleSyncRepeatingTask(final Runnable runnable, final long delay, final long interval) { return Bukkit.getScheduler().scheduleSyncRepeatingTask(Pexel.getCore(), runnable, delay, interval); } public int scheduleSyncDelayedTask(final Runnable runnable, final long delay) { return Bukkit.getScheduler().scheduleSyncDelayedTask(Pexel.getCore(), runnable, delay); } public void delay(final long delay, final Runnable runnable) { Bukkit.getScheduler().scheduleSyncDelayedTask(Pexel.getCore(), runnable, delay); } public ScheduledTask each(final long period, final Runnable runnable) { ScheduledTask task = new ScheduledTask(period, runnable); this.tasks.add(task); return task; } public void cancel(final ScheduledTask task) { this.tasks.remove(task); } public void cancelTask(final int taskId) { Bukkit.getScheduler().cancelTask(taskId); } public void tick() { this.temptasks = new ArrayList<ScheduledTask>(this.tasks); for (ScheduledTask task : this.temptasks) { if (this.elapsed % task.period == 0) { try { task.runnable.run(); } catch (Exception ex) { ex.printStackTrace(); } } } this.elapsed++; } public static final class ScheduledTask { public ScheduledTask(final long period2, final Runnable runnable2) { this.period = period2; this.runnable = runnable2; } public final Runnable runnable; public final long period; } }
3,332
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PlayerProfile.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/PlayerProfile.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlID; import javax.xml.bind.annotation.XmlRootElement; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import com.google.common.collect.ImmutableList; import eu.matejkormuth.pexel.PexelCore.util.ParticleEffect2; /** * Object for storing player's friends and unfriends. */ @XmlRootElement public class PlayerProfile { /** * Player's UUID. */ @XmlID @XmlAttribute protected final UUID uuid; /** * Player's friends. */ @XmlAttribute protected final List<UUID> friends = new ArrayList<UUID>(); /** * Player's foes. */ @XmlAttribute protected final List<UUID> foes = new ArrayList<UUID>(); /** * Player's settings. */ @XmlAttribute protected final Map<Settings, Boolean> settings = new HashMap<Settings, Boolean>(); /** * Spectating status. */ protected transient boolean spectating = false; //Dont mind this one... private ParticleEffect2 particleType; /** * Last known name of this player. */ @XmlAttribute protected String lastKnownName = ""; /** * Amount of player's points (probably in-game currency or whatever). */ @XmlAttribute protected int points = 0; @XmlAttribute protected int warnCount = 0; /** * Represents party, that player is currently in. If is player not in any party, it is null. */ protected transient Party party; /** * Creates player profile from Player object. * * @param player */ public PlayerProfile(final Player player) { this.uuid = player.getUniqueId(); } /** * Creates player profile from UUID. * * @param player */ public PlayerProfile(final UUID player) { this.uuid = player; } /** * Adds friend. * * @param player */ public void addFriend(final UUID player) { this.friends.add(player); } /** * Removes friend. * * @param player */ public void removeFriend(final UUID player) { this.friends.remove(player); } public void addFoe(final UUID player) { this.foes.add(player); } public void removeFoe(final UUID player) { this.foes.remove(player); } /** * Returns UUID of profile. * * @return */ public UUID getUniqueId() { return this.uuid; } /** * Return list of player's friends. * * @return */ public List<UUID> getFriends() { return ImmutableList.copyOf(this.friends); } public List<UUID> getFoes() { return ImmutableList.copyOf(this.foes); } /** * Returns whatever is this player friend with the specified. * * @param uniqueId * @return */ public boolean isFriend(final UUID uniqueId) { return this.friends.contains(uniqueId); } public boolean isFoe(final UUID uniqueId) { return this.foes.contains(uniqueId); } /** * Returns setting value. * * @param setting * @return */ public boolean getSetting(final Settings setting) { if (this.settings.containsKey(setting)) return this.settings.get(setting); else return true; } /** * Set players settings. * * @param setting * @param value */ public void setSetting(final Settings setting, final boolean value) { this.settings.put(setting, value); } /** * Return's whether is player spectating. * * @return */ public boolean isSpectating() { return this.spectating; } /** * Sets player's spectating state. * * @param spectating */ public void setSpectating(final boolean spectating) { this.spectating = spectating; } /** * Saves player's profile to file. * * @param path * path to save */ public void save(final String path) { YamlConfiguration yaml = new YamlConfiguration(); yaml.set("player.uuid", this.uuid.toString()); yaml.set("player.points", this.points); yaml.set("player.warnCount", this.warnCount); yaml.set("player.lastKnownName", this.lastKnownName); yaml.set("player.friends", this.friends); yaml.set("player.foes", this.foes); try { yaml.save(new File(path)); } catch (IOException e) { Log.addProblem("Can't save player profile: " + e.toString()); e.printStackTrace(); } } /** * Loads player profile from specified path. * * @param playerProfile * @return */ public static PlayerProfile load(final String path) { YamlConfiguration yaml = YamlConfiguration.loadConfiguration(new File(path)); UUID uuid = UUID.fromString(yaml.getString("player.uuid")); PlayerProfile profile = new PlayerProfile(uuid); profile.points = yaml.getInt("player.points"); profile.lastKnownName = yaml.getString("player.lastKnownName"); List<?> friends = yaml.getList("player.friends"); List<?> foes = yaml.getList("player.foes"); for (Object obj : friends) profile.addFriend(UUID.fromString(obj.toString())); for (Object obj : foes) profile.addFoe(UUID.fromString(obj.toString())); return profile; } // Will be removed public void setParticleType(final ParticleEffect2 effect) { this.particleType = effect; } // Will be removed public ParticleEffect2 getParticleType() { return this.particleType; } /** * Return the number of points. * * @return */ public int getPoints() { return this.points; } /** * Add specified amount of points. * * @param points */ public void addPoints(final int points) { this.points += points; } public void saveXML(final String profilePath) { //TODO: Not yet implemented } public Party getParty() { return this.party; } public void setParty(final Party party) { this.party = party; } }
7,764
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
MatchRecorder.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/MatchRecorder.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.arenas.AbstractArena; /** * Recording device for matches. * * @author Mato Kormuth * */ public class MatchRecorder { // TODO: FIXME: XXX: Need re-writing... //Arena that this recorder record. private final AbstractArena arena; //ID of periodic task private int taskId = 0; //Interval in ticks private final long interval = 2L; //List of frames private final List<Frame> frames = new ArrayList<Frame>(600); //Mapping UUID to player name private final Map<UUID, String> playernames = new HashMap<UUID, String>(); //Mapping UUID to EntityID private final Map<UUID, Integer> playerids = new HashMap<UUID, Integer>(); /** * Initializes new instance of record for specified arena * * @param arena * arena to initialize recorder to */ public MatchRecorder(final AbstractArena arena) { this.arena = arena; } /** * Starts periodic process of capturing frames. */ public void startCapturing() { this.arena.chatAll(ChatColor.RED + "[Record] " + ChatColor.GOLD + "Warning, this match is recorded!"); this.arena.chatAll(ChatColor.RED + "[Record] " + ChatColor.GOLD + "Recording started!"); for (Player p : this.arena.getPlayers()) { this.playernames.put(p.getUniqueId(), p.getName()); this.playerids.put(p.getUniqueId(), p.getEntityId()); } this.taskId = Pexel.getScheduler().scheduleSyncRepeatingTask(new Runnable() { @Override public void run() { MatchRecorder.this.captureFrame(); } }, 0L, this.interval); } /** * Makes snapshot of player healths and positions ak. records a frame. */ protected void captureFrame() { Frame frame = new Frame(); for (Player p : this.arena.getPlayers()) { frame.p_locations.put(p.getEntityId(), p.getLocation()); frame.p_healths.put(p.getEntityId(), ((CraftPlayer) p).getHealth()); //getHealth fix } this.frames.add(frame); } /** * Stops capturing process. */ public void stopCapturing() { this.arena.chatAll(ChatColor.RED + "[Record] " + ChatColor.GOLD + "Recording stopped!"); Pexel.getScheduler().cancelTask(this.taskId); } /** * Returns whether is recorder recording or not. * * @return true if is recorder enabled */ public boolean isEnabled() { return this.taskId != 0; } /** * Saves recorder frames to file. */ public void save() { Log.info("Saving started!"); //TODO: FIXME: Please, make this thing normal... long starttime = System.nanoTime(); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy-HH-mm-ss-SS"); String name = Paths.matchRecord(sdf.format(new Date()) + "-" + this.arena.getName().toLowerCase()); OutputStreamWriter writer = null; try { writer = new OutputStreamWriter(new FileOutputStream(new File(name))); writer.write("# MATCH RECORD INFO START\n"); writer.write("version=1\n"); writer.write("interval=" + this.interval + "\n"); writer.write("# MATCH RECORD INFO END\n"); writer.write("# MINIGAME INFO START\n"); writer.write("minigameName=" + this.arena.getMinigame().getName() + "\n"); writer.write("arenaName=" + this.arena.getName() + "\n"); writer.write("date=" + System.currentTimeMillis() + "\n"); writer.write("# MINIGAME INFO END\n"); writer.write("# NAME TRANSLATE MAP START\n"); for (Entry<UUID, String> entry : this.playernames.entrySet()) writer.write(entry.getKey().toString() + "=" + entry.getValue() + "\n"); writer.write("# NAME TRANSLATE MAP END\n"); writer.write("# ID TRANSLATE MAP START\n"); for (Entry<UUID, Integer> entry : this.playerids.entrySet()) writer.write(entry.getKey().toString() + "=" + entry.getValue() + "\n"); writer.write("# ID TRANSLATE MAP END\n"); writer.write("# FRAMES SECTION START\n"); List<Frame> frames2 = this.frames; int frameCount = frames2.size(); for (int i = 0; i < frameCount; i++) { Frame f = frames2.get(i); writer.write("# FRAME " + i + " START\n"); writer.write("# FRAME PLAYER LOCATIONS LIST START\n"); for (Entry<Integer, Location> entry : f.p_locations.entrySet()) { writer.write(entry.getKey() + "=" + entry.getValue().getX() + "|" + entry.getValue().getY() + "|" + entry.getValue().getZ() + "|" + entry.getValue().getYaw() + "|" + entry.getValue().getPitch() + "\n"); } writer.write("# FRAME PLAYER LOCATIONS LIST END\n"); writer.write("# FRAME PLAYER HEALTH LIST START\n"); for (Entry<Integer, Double> entry : f.p_healths.entrySet()) { writer.write(entry.getKey() + "=" + entry.getValue() + "\n"); } writer.write("# FRAME PLAYER HEALTH LIST END\n"); writer.write("# FRAME " + i + " END\n"); } writer.write("# FRAMES SECTION END\n"); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (IOException e) { e.printStackTrace(); } } Log.info("Saving ended! (took " + (System.nanoTime() - starttime) + " ns / " + (System.nanoTime() - starttime) / 1000 / 1000 + "ms)"); } /** * Frame. * * @author Mato Kormuth * */ public class Frame { //Various mappings. Map<Integer, Location> p_locations = new HashMap<Integer, Location>(); Map<Integer, Double> p_healths = new HashMap<Integer, Double>(); } /** * Resets recorder. */ public void reset() { this.frames.clear(); this.playerids.clear(); this.playernames.clear(); Pexel.getScheduler().cancelTask(this.taskId); } }
8,190
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Settings.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/core/Settings.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.core; import org.bukkit.entity.Player; /** * All settings. * * @author Mato Kormuth * */ public enum Settings { /** * If the music would be played at the end of music. */ ENDROUND_MUSIC, /** * Chat has sounds, when player name is in it. */ CHAT_SOUNDS; public boolean hasEnabled(final Player player) { return StorageEngine.getProfile(player.getUniqueId()).getSetting(this); } }
1,309
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
TeleportAction.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/actions/TeleportAction.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.actions; import org.bukkit.Location; import org.bukkit.entity.Player; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelNetworking.Server; /** * Inventory action that teleports player to specified location. * * @author Mato Kormuth * */ public class TeleportAction implements Action { /** * Target location. */ private final Location location; /** * Target server. */ private Server server; /** * Creates a new action. * * @param location */ public TeleportAction(final Location location) { this.location = location; } /** * Creates a new action. * * @param location */ public TeleportAction(final Location location, final Server server) { this.location = location; this.server = server; } @Override public void execute(final Player player) { if (this.server.isLocalServer()) { // Just teleport player to target location. player.teleport(this.location); } else { // TODO: Add teleport to location. Perform server-wide teleport // Teleport to other server when using Bungee. ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); out.writeUTF(this.server.getBungeeName()); player.sendPluginMessage(Pexel.getCore(), "BungeeCord", out.toByteArray()); } } }
2,477
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
CommandAction.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/actions/CommandAction.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.actions; import org.bukkit.entity.Player; /** * Basic sudo command player action. */ public class CommandAction implements Action { private String command = ""; /** * Creates a new command action. Command should <b> not contain</b> slash. <code>%player%</code> in command will be * replaced with name of player, that is this command executing for. * * @param command * command of this action */ public CommandAction(final String command) { this.command = command; } @Override public void execute(final Player player) { player.performCommand(this.command.replace("%player%", player.getName())); } }
1,563
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
OpenInventoryMenuAction.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/actions/OpenInventoryMenuAction.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.actions; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenu; /** * Inventory menu action that opens another inventory menu. */ public class OpenInventoryMenuAction implements Action { private final InventoryMenu inventoryMenu; /** * Creates new action that opens specified inventory menu when player clicks icon. * * @param im * another InventoryMenu */ public OpenInventoryMenuAction(final InventoryMenu im) { this.inventoryMenu = im; } @Override public void execute(final Player player) { this.inventoryMenu.showTo(player); } }
1,531
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
JavaArbitraryAction.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/actions/JavaArbitraryAction.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.actions; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.util.ParametrizedRunnable; /** * Menu action that will execute specified code, when triggered. */ public class JavaArbitraryAction implements Action { private final ParametrizedRunnable runnable; public JavaArbitraryAction(final ParametrizedRunnable runnable) { this.runnable = runnable; } @Override public void execute(final Player player) { this.runnable.run(player); } }
1,375
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Action.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/actions/Action.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.actions; import org.bukkit.entity.Player; /** * Class that repsresents action in PEXEL. */ public interface Action { /** * Called when action should be executed on the player. * * @param player * executor */ public void execute(Player player); }
1,155
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
UnfriendCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/UnfriendCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * @author Mato Kormuth * */ public class UnfriendCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (command.getName().equalsIgnoreCase("unfriend")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } return false; } private void processCommand(final Player sender, final String[] args) { if (args.length >= 1) { String playerName = args[0]; boolean success = false; for (Player p : Bukkit.getOnlinePlayers()) { if (p.getName().equalsIgnoreCase(playerName)) { if (StorageEngine.getProfile(sender.getUniqueId()).isFriend( p.getUniqueId())) { StorageEngine.getProfile(sender.getUniqueId()).removeFriend( p.getUniqueId()); sender.sendMessage(ChatManager.success("Player '" + p.getName() + "' has been REMOVED from your friends!")); success = true; } else { sender.sendMessage(ChatManager.error("Player '" + p.getName() + "' is not in your friends list!")); } } } if (!success) sender.sendMessage(ChatManager.error("Player not found! Player must be online!")); } else { sender.sendMessage(ChatManager.error("You must provide player name!")); } } private void processOpCommand(final Player sender, final String[] args) { //No op commands. this.processCommand(sender, args); } }
3,462
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
SettingsCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/SettingsCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Settings; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * Class used for settings. * * @author Mato Kormuth * */ public class SettingsCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (sender instanceof Player) { if (args.length == 2) { try { Settings setting = Settings.valueOf(args[0]); Boolean value = Boolean.parseBoolean(args[1]); StorageEngine.getProfile(((Player) sender).getUniqueId()).setSetting( setting, value); } catch (Exception ex) { sender.sendMessage(ChatManager.error(ex.toString())); } } else { sender.sendMessage(ChatManager.error("/settings <setting> <false/true>")); String avaiable = ChatColor.GOLD + "Avaiable settings: " + ChatColor.YELLOW; for (Settings s : Settings.values()) { avaiable += s.toString() + ", "; } sender.sendMessage(avaiable); } } return false; } }
2,518
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
SpawnCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/SpawnCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * Command executor for /spawn command * * @author Mato Kormuth * */ public class SpawnCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender paramCommandSender, final Command paramCommand, final String paramString, final String[] paramArrayOfString) { if (paramCommand.getName().equalsIgnoreCase("spawn")) { ((Player) paramCommandSender).teleport(Pexel.getHubLocation()); return true; } return false; } }
1,618
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
CommandHandler.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/CommandHandler.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used for marking class as command handler. * * @author Mato Kormuth * */ @Target({ java.lang.annotation.ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface CommandHandler { /** * The name of command that this handler handles. * * @return the name */ String name(); /** * Descrption of command. * * @return description */ String description() default ""; /** * Aliases of command * * @return aliases */ String[] aliases() default ""; }
1,575
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
AlternativeCommands.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/AlternativeCommands.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.material.Sign; import org.bukkit.util.Vector; import eu.matejkormuth.pexel.PexelCore.HardCoded; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.actions.JavaArbitraryAction; import eu.matejkormuth.pexel.PexelCore.actions.OpenInventoryMenuAction; import eu.matejkormuth.pexel.PexelCore.arenas.AbstractArena; import eu.matejkormuth.pexel.PexelCore.arenas.AdvancedArena; import eu.matejkormuth.pexel.PexelCore.arenas.DisconnectReason; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Log; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenu; import eu.matejkormuth.pexel.PexelCore.menu.InventoryMenuItem; import eu.matejkormuth.pexel.PexelCore.util.ItemUtils; import eu.matejkormuth.pexel.PexelCore.util.ParametrizedRunnable; import eu.matejkormuth.pexel.PexelCore.util.ParticleEffect2; import eu.matejkormuth.pexel.PexelCore.util.TimeBomb; /** * Alternate method of handling commands. I'm lazy to do this in plugin.yml. * * @author Mato Kormuth * */ public class AlternativeCommands implements Listener { InventoryMenu particleEffectMenu; InventoryMenu particleTypesMenu; InventoryMenu particleAmountMenu; InventoryMenu particleAnimationMenu; public AlternativeCommands() { Bukkit.getPluginManager().registerEvents(this, Pexel.getCore()); List<InventoryMenuItem> particleEffectMenuItems = new ArrayList<InventoryMenuItem>(); List<InventoryMenuItem> particleTypesMenuItems = new ArrayList<InventoryMenuItem>(); List<InventoryMenuItem> particleAmountMenuItems = new ArrayList<InventoryMenuItem>(); List<InventoryMenuItem> particleAnimationMenuItems = new ArrayList<InventoryMenuItem>(); ParticleEffect2[] values = ParticleEffect2.values(); for (int i = 0; i < values.length; i++) { final ParticleEffect2 effect = values[i]; particleTypesMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.NETHER_STAR, effect.toString(), null), new JavaArbitraryAction(new ParametrizedRunnable() { @Override public void run(final Object... args) { StorageEngine.getProfile((((Player) args[0]).getUniqueId())) .setParticleType(effect); } }), i, true)); } this.particleTypesMenu = new InventoryMenu(54, "Particle type", particleTypesMenuItems); particleAmountMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.BOOK, "Few particles", null), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { } }), 0, true)); particleAmountMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.BOOK, "The right amount", null), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { } }), 1, true)); particleAmountMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.BOOK, "Many particles", null), new JavaArbitraryAction( new ParametrizedRunnable() { @Override public void run(final Object... args) { } }), 2, true)); this.particleAmountMenu = new InventoryMenu(InventoryType.CHEST, "Particle amount", particleAmountMenuItems); this.particleAnimationMenu = new InventoryMenu(InventoryType.CHEST, "Particle animation", particleAnimationMenuItems); particleEffectMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.NETHER_STAR, "Particle types", null), new OpenInventoryMenuAction(this.particleTypesMenu), 0, false)); particleEffectMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.BOOK, "Particle amount", null), new OpenInventoryMenuAction( this.particleAmountMenu), 1, false)); particleEffectMenuItems.add(new InventoryMenuItem(ItemUtils.namedItemStack( Material.FIRE, "Particle animation", null), new OpenInventoryMenuAction( this.particleAnimationMenu), 2, false)); this.particleEffectMenu = new InventoryMenu(InventoryType.CHEST, "Particle effects", particleEffectMenuItems); } @SuppressWarnings("deprecation") @EventHandler private void onPrepocessCommand(final PlayerCommandPreprocessEvent event) { List<String> args = new ArrayList<String>(); String[] d = event.getMessage().split(" "); for (int i = 1; i < d.length; i++) { args.add(d[i]); } Player sender = event.getPlayer(); String command = d[0]; Log.info(sender.getName() + " issued command " + event.getMessage() + " at " + event.getPlayer().getLocation().getX() + "," + event.getPlayer().getLocation().getY() + "," + event.getPlayer().getLocation().getZ() + "," + event.getPlayer().getLocation().getWorld().getName()); if (command.contains("/getcock") || command.contains("/magiccock")) { sender.getInventory().addItem(Pexel.getMagicClock().getClock()); } else if (command.contains("/gravity")) { HardCoded.antigravity = new Vector(0, Float.parseFloat(args.get(0)), 0); } else if (command.contains("/forcestart")) { for (AbstractArena arena : StorageEngine.getArenas().values()) { if (arena instanceof AdvancedArena) { if (arena.contains(sender)) { sender.sendMessage(ChatColor.LIGHT_PURPLE + "Forcing onGameStart()..."); ((AdvancedArena) arena).onGameStart(); } } } } else if (command.contains("/forcereset")) { for (AbstractArena arena : StorageEngine.getArenas().values()) { if (arena instanceof AdvancedArena) { if (arena.contains(sender)) { sender.sendMessage(ChatColor.LIGHT_PURPLE + "Forcing reset()..."); ((AdvancedArena) arena).reset(); } } } } else if (command.equalsIgnoreCase("/leave") || command.equalsIgnoreCase("/lobby")) { for (AbstractArena arena : StorageEngine.getArenas().values()) { if (arena.contains(event.getPlayer())) { arena.onPlayerLeft(event.getPlayer(), DisconnectReason.PLAYER_LEAVE); sender.sendMessage(ChatManager.error("Left " + arena.getMinigame().getDisplayName() + " arena!")); } } event.getPlayer().getInventory().clear(); event.getPlayer().setMaxHealth(20D); event.getPlayer().setHealth(20D); event.getPlayer().setFoodLevel(20); event.getPlayer().teleport(Pexel.getHubLocation()); } else if (command.equalsIgnoreCase("list_arena_aliases")) { for (String key : StorageEngine.getAliases().keySet()) { sender.sendMessage(ChatColor.BLUE + key + ChatColor.WHITE + " = " + ChatColor.GREEN + StorageEngine.getByAlias(key).getName()); } } else if (command.contains("/version") || command.contains("/pcversion")) { try { //String version = IOUtils.toString(this.getClass().getResourceAsStream( // "../versionFile.txt")); //sender.sendMessage(ChatColor.DARK_RED // + "This server is running Pexel-Core version " + version); } catch (Exception e) { e.printStackTrace(); sender.sendMessage(ChatColor.RED + "Error while trying to get version! Check your build!"); } } else if (command.contains("/particles")) { this.particleEffectMenu.showTo(sender); } else if (command.contains("/timebomb")) { sender.getLocation().getBlock().setType(Material.TNT); Block b = sender.getLocation().getBlock().getRelative(BlockFace.NORTH); b.setType(Material.WALL_SIGN); ((Sign) b.getState().getData()).setFacingDirection(BlockFace.NORTH.getOppositeFace()); new TimeBomb(sender.getLocation().getBlock(), b, 60); } else if (command.contains("/grassgen")) { int i = 3; boolean remove = false; boolean flowers = false; boolean longgrass = false; World w = sender.getWorld(); Location pLoc = sender.getLocation(); sender.sendMessage(ChatColor.GREEN + "/grassgen <radius> <flowers?> <longgrass?>"); sender.sendMessage(ChatColor.YELLOW + "Specify negative radius for remove, positive for generation."); if (args.size() > 0) { i = Integer.parseInt(args.get(0)); if (i < 0) { remove = true; i = -i; } } if (args.size() == 3) { flowers = Boolean.parseBoolean(args.get(1)); longgrass = Boolean.parseBoolean(args.get(2)); } if (!remove) { sender.sendMessage(ChatColor.YELLOW + "Generating.."); for (int x = -i; x <= i; x++) { for (int z = -i; z <= i; z++) { double cX = pLoc.getX() + (x); double cZ = pLoc.getZ() + (z); double cY = sender.getWorld().getHighestBlockYAt((int) cX, (int) cZ); Block b = w.getBlockAt((int) cX, (int) cY, (int) cZ); //Generate grass and flowers. switch (Pexel.getRandom().nextInt(6)) { case 0: //Air break; case 1: b.setType(Material.LONG_GRASS); b.setData((byte) 1); break; case 2: if (longgrass) { if (Pexel.getRandom().nextBoolean()) { b.setType(Material.DOUBLE_PLANT); b.setData((byte) 2); b.getRelative(BlockFace.UP).setType( Material.DOUBLE_PLANT); b.getRelative(BlockFace.UP).setData((byte) 8); } else { b.setType(Material.DOUBLE_PLANT); b.setData((byte) 3); b.getRelative(BlockFace.UP).setType( Material.DOUBLE_PLANT); b.getRelative(BlockFace.UP).setData((byte) 8); } } else { b.setType(Material.LONG_GRASS); b.setData((byte) 1); } break; case 3: b.setType(Material.LONG_GRASS); b.setData((byte) 1); break; case 4: b.setType(Material.LONG_GRASS); b.setData((byte) 1); break; case 5: if (flowers) { switch (Pexel.getRandom().nextInt(9)) { case 0: b.setType(Material.RED_ROSE); break; case 1: b.setType(Material.YELLOW_FLOWER); break; case 2: b.setType(Material.RED_ROSE); b.setData((byte) 1); break; case 3: b.setType(Material.RED_ROSE); b.setData((byte) 2); break; case 4: b.setType(Material.RED_ROSE); b.setData((byte) 3); break; case 5: b.setType(Material.RED_ROSE); b.setData((byte) 4); break; case 6: b.setType(Material.RED_ROSE); b.setData((byte) 5); break; case 7: b.setType(Material.RED_ROSE); b.setData((byte) 6); break; case 8: b.setType(Material.RED_ROSE); b.setData((byte) 7); break; case 9: b.setType(Material.RED_ROSE); b.setData((byte) 8); break; } } else { b.setType(Material.LONG_GRASS); b.setData((byte) 2); } break; case 6: //Air break; } } } } else { sender.sendMessage(ChatColor.YELLOW + "Removing.."); //Remove everything for (int x = -i; x <= i; x++) { for (int z = -i; z <= i; z++) { double cX = pLoc.getX() + (x); double cZ = pLoc.getZ() + (z); double cY = sender.getWorld().getHighestBlockYAt((int) cX, (int) cZ); Block b = w.getBlockAt((int) cX, (int) cY, (int) cZ); Material mat = b.getType(); if (mat == Material.LONG_GRASS || mat == Material.DOUBLE_PLANT || mat == Material.RED_ROSE || mat == Material.YELLOW_FLOWER) { b.setType(Material.AIR); } } } } } } }
18,172
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
FriendCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/FriendCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * Class used for handling 'friends' command. * * @author Mato Kormuth * */ public class FriendCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (command.getName().equalsIgnoreCase("friend")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } return false; } private void processCommand(final Player sender, final String[] args) { if (args.length >= 1) { String playerName = args[0]; boolean success = false; for (Player p : Bukkit.getOnlinePlayers()) { if (p.getName().equalsIgnoreCase(playerName)) { StorageEngine.getProfile(sender.getUniqueId()).addFriend( p.getUniqueId()); sender.sendMessage(ChatManager.success("Player '" + p.getName() + "' has been ADDED to your friends!")); p.sendMessage(ChatManager.success("Player '" + sender.getName() + "' added you to his/her friends! Add him too! /friend " + sender.getName())); success = true; } } if (!success) sender.sendMessage(ChatManager.error("Player not found! Player must be online!")); } else { sender.sendMessage(ChatManager.error("You must provide player name!")); } } private void processOpCommand(final Player sender, final String[] args) { //No op commands. this.processCommand(sender, args); } }
3,318
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PCMDCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/PCMDCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; /** * PCMD (internal pexel command) executor. * * @author Mato Kormuth * */ public class PCMDCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { if (sender instanceof Player) { //Player psender = (Player) sender; if (args.length == 1) { //String arg_command = args[0]; } } return true; } }
1,540
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
CommandManager.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/CommandManager.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Log; import eu.matejkormuth.util.AnnotationNotPresentException; /** * Class that is used for dynamic command registration. */ public class CommandManager { /** * Map of subcommands. */ private final Map<String, Map<String, Method>> subcommands = new HashMap<String, Map<String, Method>>(); /** * Map of commands. */ private final Map<String, Object> commands = new HashMap<String, Object>(); /** * Map of command aliases. */ private final Map<String, String> aliases = new HashMap<String, String>(); public CommandManager() { } /** * Tries to register specified object as command handler. * * @param command * command handler */ public void registerCommands(final Object command) { Log.info("Register command on object: " + command.getClass().getSimpleName() + "#" + command.hashCode()); Class<?> clazz = command.getClass(); if (clazz.isAnnotationPresent(CommandHandler.class)) { this.registerCommand(command); this.registerAliases(clazz); for (Method method : clazz.getDeclaredMethods()) { if (method.isAnnotationPresent(SubCommand.class)) { this.registerSubcommand(command, method); } } } else { throw new AnnotationNotPresentException("Annotation: Command; Class: clazz"); } } /** * Parses command from string and tries to execute it as specified player. * * @param sender * executor * @param command * command */ public boolean parseCommand(final Player sender, final String command) { String parts[] = command.trim().split("\\s+"); String baseCommand = parts[0]; if (this.commands.containsKey(baseCommand.toLowerCase())) { if (this.hasPermission(sender, baseCommand)) { //If no subcommand if (parts.length == 1) { this.invoke(this.commands.get(baseCommand), this.subcommands.get(baseCommand).get("main"), sender); return true; } else { String subCommand = parts[1]; if (this.subcommands.get(baseCommand).containsKey(subCommand)) { if (this.hasPermission(sender, baseCommand + "." + subCommand)) { //Executing subcommand if (parts.length == 2) { this.invoke( this.commands.get(baseCommand), this.subcommands.get(baseCommand).get(subCommand), sender); return true; } else { Object[] args = new String[parts.length - 2]; System.arraycopy(parts, 2, args, 0, parts.length - 2); this.invoke( this.commands.get(baseCommand), this.subcommands.get(baseCommand).get(subCommand), sender, args); return true; } } else { sender.sendMessage(ChatManager.error("You don't have permission!")); return true; } } else { if (subCommand.equalsIgnoreCase("help")) { sender.sendMessage(ChatColor.YELLOW + "Command help: " + baseCommand); for (Method m : this.subcommands.get(baseCommand).values()) { SubCommand annotation = m.getAnnotation(SubCommand.class); String scArgs = ""; for (Class<?> param : m.getParameterTypes()) scArgs += "<[" + param.getSimpleName() + "]> "; String scName = m.getName(); if (!annotation.name().equals("")) scName = annotation.name(); sender.sendMessage(ChatColor.BLUE + "/" + baseCommand + ChatColor.RED + " " + scName + " " + ChatColor.GOLD + scArgs + ChatColor.GREEN + "- " + annotation.description()); } return true; } else { if (this.hasPermission(sender, baseCommand + "." + subCommand)) { Object[] args = new String[parts.length - 1]; System.arraycopy(parts, 1, args, 0, parts.length - 1); this.invoke(this.commands.get(baseCommand), this.subcommands.get(baseCommand).get("main"), sender, args); return true; } else { sender.sendMessage(ChatManager.error("You don't have permission!")); return true; } } } } } else { sender.sendMessage(ChatManager.error("You don't have permission!")); return true; } } else { //sender.sendMessage(ChatManager.error("Unknown command!")); return false; } } /** * Returns whether specified player has permission to specififed command. * * @param sender * player * @param baseCommand * command * @return true or false */ private boolean hasPermission(final Player sender, final String node) { return true; } /** * Invokes specified subcommand of command on specififed player weith specified arguments. * * @param command * command * @param subcommand * sub command * @param invoker * player * @param args * args */ private void invoke(final Object command, final Method subcommand, final Player invoker, final Object... args) { try { String argsString = "["; if (args != null) for (Object o : args) argsString += o.toString() + ","; if (argsString.length() > 1) argsString = argsString.substring(0, argsString.length() - 1); String name = command.getClass().getAnnotation(CommandHandler.class).name(); Log.info("Invoking command '" + name + "(" + command.getClass().getSimpleName() + ") -> " + subcommand.getAnnotation(SubCommand.class).name() + " (" + subcommand.getName() + ")' on player '" + invoker.getName() + "' with args: " + argsString + "]"); if (!Arrays.asList(command.getClass().getDeclaredMethods()).contains( subcommand)) Log.warn("Subcommand is not method of command class."); if (args.length == 0) { subcommand.invoke(command, invoker); } else { if (this.validParams(subcommand, args)) { Log.info(" Invoking: Player, " + args.length); Object[] objs = new Object[args.length + 1]; objs[0] = invoker; System.arraycopy(args, 0, objs, 1, args.length); subcommand.invoke(command, objs); } else invoker.sendMessage(ChatManager.error("Unknown command: invalid params")); } } catch (IllegalArgumentException e) { e.printStackTrace(); invoker.sendMessage(ChatManager.error("Unknown command: " + e.getMessage())); if (invoker.isOp()) invoker.sendMessage(ChatManager.error(e.toString())); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); invoker.sendMessage(ChatManager.error("Internal server error occured while attempting to execute this command!")); throw new RuntimeException(e); } } private boolean validParams(final Method subcommand, final Object[] args) { Class<?>[] parameterTypes = subcommand.getParameterTypes(); if (args.length > parameterTypes.length - 1) return false; for (int i = 1; i < parameterTypes.length; i++) { Class<?> parameterType = parameterTypes[i]; Log.info(" Validating param #" + i + ": " + parameterType.getSimpleName() + " == " + args[i - 1].getClass().getSimpleName()); if (!args[i - 1].getClass().equals(parameterType)) return false; } return true; } private void registerSubcommand(final Object command, final Method method) { String baseCommand = command.getClass().getAnnotation(CommandHandler.class).name().toLowerCase(); String subCommand = method.getName().toLowerCase(); if (!method.getAnnotation(SubCommand.class).name().equalsIgnoreCase("")) subCommand = method.getAnnotation(SubCommand.class).name().toLowerCase(); Log.info(" Register subcommand: " + baseCommand + " -> " + subCommand + "#" + method.hashCode()); if (!method.isAccessible()) method.setAccessible(true); this.subcommands.get(baseCommand).put(subCommand, method); } private void registerCommand(final Object object) { String baseCommand = object.getClass().getAnnotation(CommandHandler.class).name().toLowerCase(); Log.info(" Register command: " + baseCommand); this.commands.put(baseCommand, object); this.subcommands.put(baseCommand, new HashMap<String, Method>()); } private void registerAliases(final Class<?> clazz) { String baseName = clazz.getAnnotation(CommandHandler.class).name(); for (String alias : clazz.getAnnotation(CommandHandler.class).aliases()) { this.aliases.put(baseName, alias); } } }
12,465
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
LoginCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/LoginCommand.java
package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; public class LoginCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { if (command.getName().equalsIgnoreCase("lobbyarena")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } sender.sendMessage(ChatManager.error("Wrong use!")); return true; } private void processCommand(final Player sender, final String[] args) { if (args.length != 1) sender.sendMessage(ChatManager.error("Wrong use! Syntax: /login <password>")); else Pexel.getAuth().authenticateCommand(sender, args[0]); } private void processOpCommand(final Player sender, final String[] args) { this.processCommand(sender, args); } }
1,543
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
LobbyCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/LobbyCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import eu.matejkormuth.pexel.PexelCore.areas.Lobby; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Region; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * Class used for evaulating /lobby commands. * * @author Mato Kormuth * */ public class LobbyCommand implements CommandExecutor { private final WorldEditPlugin we; public LobbyCommand() { this.we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin( "WorldEdit"); } @Override public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { if (command.getName().equalsIgnoreCase("lobbyarena")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } sender.sendMessage(ChatManager.error("Wrong use!")); return true; } private void processCommand(final Player sender, final String[] args) { sender.sendMessage(ChatManager.error("Permission denied!")); } private void processOpCommand(final Player sender, final String[] args) { if (args.length >= 2) { String actionName = args[0]; String lobbyName = args[1]; if (actionName.equalsIgnoreCase("create")) { if (this.checkSelection(sender)) { Region region = new Region(this.we.getSelection(sender)); StorageEngine.addLobby(new Lobby(lobbyName, region)); sender.sendMessage(ChatManager.success("Lobby '" + lobbyName + "' has been created!")); } } else if (actionName.equalsIgnoreCase("setspawn")) { StorageEngine.getLobby(lobbyName).setSpawn(sender.getLocation()); sender.sendMessage(ChatManager.success("Spawn of lobby '" + lobbyName + "' has been set to your position.")); } else { sender.sendMessage(ChatManager.error("Invalid action!")); } } else { sender.sendMessage(ChatManager.error("/lobby create <name>")); sender.sendMessage(ChatManager.error("/lobby setspawn <name>")); } } private boolean checkSelection(final Player sender) { if (this.we.getSelection(sender) != null) return true; else { sender.sendMessage(ChatManager.error("Make a WorldEdit selection first!")); return false; } } }
4,108
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
QJCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/QJCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.util.Arrays; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; import eu.matejkormuth.pexel.PexelCore.matchmaking.MatchmakingRequest; /** * Class that is here for /qj command. * * @author Mato Kormuth * */ public class QJCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (command.getName().equalsIgnoreCase("qj")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } sender.sendMessage(ChatManager.error("Wrong use!")); return true; } private void processCommand(final Player sender, final String[] args) { if (args.length == 0) { Pexel.getMatchmaking().registerRequest( new MatchmakingRequest(Arrays.asList(sender), null, null)); sender.sendMessage(ChatManager.success("Successfully joined matchmaking!")); } else if (args.length == 1) { if (StorageEngine.getMinigame(args[0]) != null) { Pexel.getMatchmaking().registerRequest( new MatchmakingRequest(Arrays.asList(sender), StorageEngine.getMinigame(args[0]), null)); sender.sendMessage(ChatManager.success("Successfully joined matchmaking!")); } else { sender.sendMessage(ChatManager.error("QJ: That minigame does not exists!")); } } else if (args.length == 2) { sender.sendMessage(ChatManager.error("QJ: Not avaiable at this time!")); } else { sender.sendMessage(ChatManager.error("/qj [minigame] [map]")); } } private void processOpCommand(final Player sender, final String[] args) { this.processCommand(sender, args); } }
3,437
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
MatchmakingCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/MatchmakingCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.util.Arrays; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.arenas.AbstractArena; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Party; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; import eu.matejkormuth.pexel.PexelCore.matchmaking.MatchmakingRequest; @CommandHandler(name = "matchmaking") public class MatchmakingCommand { @SubCommand public void main(final Player sender) { sender.sendMessage(ChatColor.YELLOW + "Cool! Now try /matchmaking help!"); } @SubCommand(description = "joins specified arena") public void joinarena(final Player sender, final String arenaname) { AbstractArena arena = StorageEngine.getArena(arenaname); if (arena != null) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() != null) { Party party = StorageEngine.getProfile(sender.getUniqueId()).getParty(); if (party.isOwner(sender)) { for (Player p : party.getPlayers()) p.sendMessage(ChatColor.YELLOW + "Your party joined matchmaking!"); Pexel.getMatchmaking().registerRequest( party.toRequest(arena.getMinigame(), arena)); } else { sender.sendMessage(ChatManager.error("You cannot join games while you are in party!")); } } else { sender.sendMessage(ChatColor.YELLOW + "Your have joined matchmaking!"); MatchmakingRequest request = new MatchmakingRequest( Arrays.asList(sender), arena.getMinigame(), arena); Pexel.getMatchmaking().registerRequest(request); } } else { sender.sendMessage(ChatManager.error("You cannot join games while you are in party!")); } } @SubCommand(description = "joins random arena with specified minigame") public void joingame(final Player sender, final String minigame) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() != null) { Party party = StorageEngine.getProfile(sender.getUniqueId()).getParty(); if (party.isOwner(sender)) { for (Player p : party.getPlayers()) p.sendMessage(ChatColor.YELLOW + "Your party joined matchmaking!"); Pexel.getMatchmaking().registerRequest( party.toRequest(StorageEngine.getMinigame(minigame), null)); } else { sender.sendMessage(ChatManager.error("You cannot join games while you are in party!")); } } else { sender.sendMessage(ChatColor.YELLOW + "Your have joined matchmaking!"); MatchmakingRequest request = new MatchmakingRequest(Arrays.asList(sender), StorageEngine.getMinigame(minigame), null); Pexel.getMatchmaking().registerRequest(request); } } }
4,075
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
SubCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/SubCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** * Annotation used for marking subcomamnds. Must be used in class, that have annotation of {@link CommandHandler}. * * @author Mato Kormuth * */ @Target({ java.lang.annotation.ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) public @interface SubCommand { /** * Name of subcommand. * * @return the name */ String name() default ""; /** * Description of command. * * @return description */ String description() default ""; }
1,503
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BukkitCommandManager.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/BukkitCommandManager.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import eu.matejkormuth.pexel.PexelCore.Pexel; /** * Command manager class that supports bukkit commands API. */ public class BukkitCommandManager extends CommandManager implements Listener { /** * Initializes new instance of {@link CommandManager} that supports bukkit. */ public BukkitCommandManager() { Bukkit.getPluginManager().registerEvents(this, Pexel.getCore()); } @EventHandler public void onCommandPreprocess(final PlayerCommandPreprocessEvent event) { if (event.getMessage().startsWith("/")) { boolean success = this.parseCommand(event.getPlayer(), event.getMessage().substring(1)); if (success) event.setCancelled(true); } else { boolean success = this.parseCommand(event.getPlayer(), event.getMessage()); if (success) event.setCancelled(true); } } }
1,980
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ChannelCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/ChannelCommand.java
package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatChannel; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.chat.PlayerChannelSubscriber; import eu.matejkormuth.pexel.PexelCore.chat.SubscribeMode; /** * Class that handles execution of /channel commands. */ @CommandHandler(name = "channel") public class ChannelCommand { @SubCommand(description = "Displays information about channels you are in.") public void main(final Player sender) { sender.sendMessage(ChatColor.GOLD + "Your channels: "); for (ChatChannel channel : ChatManager.getChannelsByPlayer(sender)) { sender.sendMessage(channel.getName()); } sender.sendMessage(ChatColor.AQUA + "/channel help - Displays help information."); } @SubCommand(description = "Lists all avaiable chat channels.") public void list(final Player sender) { sender.sendMessage(ChatColor.GREEN + "Avaiable channels: "); for (ChatChannel channel : ChatManager.getChannelsByPlayer(sender)) { if (channel.isPublic()) sender.sendMessage(channel.getName()); } } @SubCommand(description = "Joins specified chat channel.") public void join(final Player sender, final String channelName) { if (ChatManager.getChannel(channelName) != null) if (!ChatManager.getChannel(channelName).isSubscribed(sender)) ChatManager.getChannel(channelName).subscribe( new PlayerChannelSubscriber(sender, SubscribeMode.READ)); else sender.sendMessage(ChatManager.error("You are already in that channel!")); else sender.sendMessage(ChatManager.error("That channel does not exists!")); } @SubCommand(description = "Lefts specified chat channel.") public void leave(final Player sender, final String channelName) { if (ChatManager.getChannel(channelName).isSubscribed(sender)) ChatManager.getChannel(channelName).unsubscribe(sender); else sender.sendMessage(ChatManager.error("You are not in that channel!")); } }
2,308
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ArenaCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/ArenaCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.areas.AreaFlag; import eu.matejkormuth.pexel.PexelCore.areas.ProtectedArea; import eu.matejkormuth.pexel.PexelCore.arenas.AbstractArena; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Region; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; import eu.matejkormuth.pexel.PexelCore.matchmaking.GameState; import eu.matejkormuth.pexel.PexelCore.minigame.Minigame; /** * Class used for /arena command. * * @author Mato Kormuth * */ public class ArenaCommand implements CommandExecutor { private final WorldEditPlugin we; public ArenaCommand() { this.we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin( "WorldEdit"); } @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (command.getName().equalsIgnoreCase("arena")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } sender.sendMessage(ChatManager.error("Wrong use!")); return true; } private void processCommand(final Player sender, final String[] args) { sender.sendMessage(ChatManager.error("Permission denied!")); } @SuppressWarnings({ "rawtypes", "unchecked", "deprecation" }) private void processOpCommand(final Player sender, final String[] args) { if (args.length > 2) { String actionName = args[0].toLowerCase(); String arenaName = args[1].toLowerCase(); if (actionName.equalsIgnoreCase("create")) { if (args.length == 4) { if (this.checkSelection(sender)) { Region region = new Region(this.we.getSelection(sender)); String arenaType = args[2]; String minigameName = args[3]; //Check if minigame exists. if (StorageEngine.getMinigame(minigameName) == null) { sender.sendMessage(ChatManager.error("Minigame not defined: " + minigameName)); return; } String className = null; Class classType = null; //Try to get by alias if ((classType = StorageEngine.getByAlias(arenaType)) == null) className = arenaType; //Build object. try { Class c = null; if (className != null) c = Class.forName(className); else c = classType; //Create instance AbstractArena newArena = (AbstractArena) c.getDeclaredConstructor( Minigame.class, String.class, Region.class, int.class).newInstance( StorageEngine.getMinigame(minigameName), arenaName, region, 16); sender.sendMessage(ChatManager.success("Created new arena with 16 slots.")); //Register arena to plugin. Pexel.getMatchmaking().registerArena(newArena); StorageEngine.addArena(newArena); } catch (Exception e) { e.printStackTrace(); sender.sendMessage(ChatManager.error("Create command failed: " + e.toString())); } } } else { sender.sendMessage(ChatManager.error("/arena create <name> <arenaClass> <minigameClass>")); } } else if (actionName.equalsIgnoreCase("edit")) { String editAction = args[2]; if (editAction.equalsIgnoreCase("gflag")) { if (args.length >= 5) { String flagName = args[3]; try { Boolean flagValue = Boolean.parseBoolean(args[4]); if (StorageEngine.getArena(arenaName) != null) { StorageEngine.getArena(arenaName).setGlobalFlag( AreaFlag.valueOf(flagName), flagValue); sender.sendMessage(ChatManager.success("Flag '" + flagName + "' set to '" + flagValue + "' in arena " + arenaName)); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("Edit command failed: " + ex.toString())); } } else { sender.sendMessage(ChatManager.error("/arena edit <name> gflag <flag> <value>")); } } else if (editAction.equalsIgnoreCase("pflag")) { if (args.length >= 5) { String flagName = args[3]; String playerName = args[4]; try { Boolean flagValue = Boolean.parseBoolean(args[5]); UUID uuid = null; if (Bukkit.getPlayerExact(playerName).isOnline()) { uuid = Bukkit.getPlayerExact(playerName).getUniqueId(); } else { throw new RuntimeException("Play offline: " + playerName); } if (StorageEngine.getArena(arenaName) != null) { StorageEngine.getArena(arenaName).setPlayerFlag( AreaFlag.valueOf(flagName), flagValue, uuid); sender.sendMessage(ChatManager.success("Flag '" + flagName + "' set to '" + flagValue + "' in arena " + arenaName + " for player " + playerName)); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("Edit command failed: " + ex.toString())); } } else { sender.sendMessage(ChatManager.error("/arena edit <name> pflag <flag> <value>")); } } else if (editAction.equalsIgnoreCase("slots")) { if (args.length >= 4) { Integer slotCount = Integer.parseInt(args[3]); try { if (StorageEngine.getArena(arenaName) != null) { StorageEngine.getArena(arenaName).setSlots(slotCount); sender.sendMessage(ChatManager.success("Slots set to '" + slotCount + "' in arena " + arenaName)); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("Slots command failed: " + ex.toString())); } } else { sender.sendMessage(ChatManager.error("/arena edit <name> slots <count>")); } } else if (editAction.equalsIgnoreCase("option")) { if (args.length >= 5) { String optionName = args[3]; String optionValue = args[4]; try { if (StorageEngine.getArena(arenaName) != null) { boolean set = false; AbstractArena arena = StorageEngine.getArena(arenaName); Field[] fields = arena.getClass().getDeclaredFields(); for (Field f : fields) { Class<?> type = f.getType(); if (!f.isAccessible()) f.setAccessible(true); if (type.equals(Integer.class) || type.equals(int.class)) { f.set(arena, Integer.parseInt(optionValue)); sender.sendMessage(ChatManager.success("Type: Integer")); set = true; } else if (type.equals(Double.class) || type.equals(double.class)) { f.set(arena, Double.parseDouble(optionValue)); sender.sendMessage(ChatManager.success("Type: Double")); set = true; } else if (type.equals(Float.class) || type.equals(float.class)) { f.set(arena, Float.parseFloat(optionValue)); sender.sendMessage(ChatManager.success("Type: Float")); set = true; } else if (type.equals(Long.class) || type.equals(long.class)) { f.set(arena, Long.parseLong(optionValue)); sender.sendMessage(ChatManager.success("Type: Long")); set = true; } else if (type.equals(Short.class) || type.equals(short.class)) { f.set(arena, Short.parseShort(optionValue)); sender.sendMessage(ChatManager.success("Type: Short")); set = true; } else if (type.equals(Byte.class) || type.equals(byte.class)) { f.set(arena, Byte.parseByte(optionValue)); sender.sendMessage(ChatManager.success("Type: Byte")); set = true; } else if (type.equals(Boolean.class) || type.equals(boolean.class)) { f.set(arena, Boolean.parseBoolean(optionValue)); sender.sendMessage(ChatManager.success("Type: Boolean")); set = true; } else if (type.equals(String.class)) { f.set(arena, optionValue); sender.sendMessage(ChatManager.success("Type: String")); set = true; } else if (type.equals(Location.class)) { f.set(arena, sender.getLocation()); sender.sendMessage(ChatManager.success("Type: Location. Taking your location as argument!")); set = true; } else { sender.sendMessage(ChatManager.error("I don't know how to set type '" + type.getName() + "'!")); sender.sendMessage(ChatManager.error("If you believe, this is an error, create bug tickes at http://bugs.mertex.eu.")); } break; } if (set) sender.sendMessage(ChatManager.success("Value of '" + optionName + "' set to '" + optionValue + "'!")); else sender.sendMessage(ChatManager.error("Option probably not found! Contact minigame author to provide valid OPTION mapping!")); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("Option command failed: " + ex.toString())); } } else { sender.sendMessage(ChatManager.error("/arena edit <name> option <optionName> <optionValue>")); } } else if (editAction.equalsIgnoreCase("options")) { try { if (StorageEngine.getArena(arenaName) != null) { sender.sendMessage(ChatColor.GOLD + "======= OPTIONS ======="); AbstractArena arena = StorageEngine.getArena(arenaName); for (Field f : arena.getClass().getDeclaredFields()) { if (f.isAccessible()) f.setAccessible(true); if (Modifier.isFinal(f.getModifiers())) sender.sendMessage(ChatColor.RED + "[READONLY]" + ChatColor.YELLOW + f.getName() + ChatColor.WHITE + " = " + ChatColor.GREEN + f.get(arena).toString()); else { if (f.get(arena) != null) sender.sendMessage(ChatColor.AQUA + "[" + f.getType().getSimpleName() + "] " + ChatColor.GREEN + f.getName() + ChatColor.WHITE + " = " + ChatColor.GREEN + f.get(arena).toString()); else sender.sendMessage(ChatColor.AQUA + "[" + f.getType().getSimpleName() + "] " + ChatColor.GREEN + f.getName() + ChatColor.WHITE + " = " + ChatColor.GREEN + "null"); } } } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("Options command failed: " + ex.toString())); } } else if (editAction.equalsIgnoreCase("invokeMethod")) { if (args.length >= 4) { String methodName = args[3]; try { if (StorageEngine.getArena(arenaName) != null) { sender.sendMessage("Invoking..."); StorageEngine.getArena(arenaName).getClass().getDeclaredMethod( methodName, (Class<?>[]) null).invoke( StorageEngine.getArena(arenaName), (Object[]) null); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("State command failed: " + ex.toString())); } } else { sender.sendMessage("Wrong use!"); } } else if (editAction.equalsIgnoreCase("state")) { if (args.length >= 4) { String state = args[3]; GameState stateToSet; try { if (state.equalsIgnoreCase("open")) { stateToSet = GameState.WAITING_EMPTY; } else if (state.equalsIgnoreCase("closed")) { stateToSet = GameState.DISABLED; } else { stateToSet = GameState.valueOf(state); } if (StorageEngine.getArena(arenaName) != null) { StorageEngine.getArena(arenaName).setState(stateToSet); sender.sendMessage(ChatManager.success("State set to '" + stateToSet.toString() + "' in arena " + arenaName)); } else { throw new RuntimeException("Arena not found: " + arenaName); } } catch (Exception ex) { ex.printStackTrace(); sender.sendMessage(ChatManager.error("State command failed: " + ex.toString())); } } else { sender.sendMessage(ChatManager.error("/arena edit <name> state (open/closed)/(WAITING_EMPTY)")); } } else { sender.sendMessage(ChatManager.error("Unknown command!")); } } else if (actionName.equalsIgnoreCase("list")) { for (ProtectedArea a : StorageEngine.getAreas().values()) { sender.sendMessage(ChatColor.YELLOW + "PA:" + a.getName()); } for (AbstractArena a : StorageEngine.getArenas().values()) { sender.sendMessage(ChatColor.GREEN + "MA:" + a.getName()); } } else { sender.sendMessage(ChatManager.error("Valid subcommands are: create, edit, list")); } } else { sender.sendMessage(ChatManager.error("Wrong use!")); } } private boolean checkSelection(final Player sender) { if (this.we.getSelection(sender) != null) return true; else { sender.sendMessage(ChatManager.error("Make a WorldEdit selection first!")); return false; } } }
23,662
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BansCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/BansCommand.java
package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.libs.joptsimple.internal.Strings; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.bans.PlayerBan; import eu.matejkormuth.pexel.PexelCore.bans.BanUtils; import eu.matejkormuth.pexel.PexelCore.bans.NamedBanAuthor; import eu.matejkormuth.pexel.PexelNetworking.Server; @CommandHandler(name = "bans") public class BansCommand { @SubCommand(description = "main command, does nothing") public void main(final Player sender) { } @SuppressWarnings("deprecation") @SubCommand(description = "Adds ban") public void add(final Player sender, final String playerName, final String... reason) { PlayerBan ban = new PlayerBan(Strings.join(reason, " "), new NamedBanAuthor( sender.getName()), Bukkit.getPlayer(playerName), Server.THIS_SERVER); Pexel.getBans().addBan(ban); Bukkit.getPlayer(playerName).kickPlayer(BanUtils.formatBannedMessage(ban)); sender.sendMessage("You have banned player " + playerName + " permanently for " + Strings.join(reason, " ")); } @SuppressWarnings("deprecation") @SubCommand(description = "Adds ban") public void add(final Player sender, final String playerName, final String lenght, final String... reason) { PlayerBan ban = new PlayerBan(Integer.parseInt(lenght), Strings.join(reason, " "), new NamedBanAuthor(sender.getName()), Bukkit.getPlayer(playerName), Server.THIS_SERVER); Pexel.getBans().addBan(ban); Bukkit.getPlayer(playerName).kickPlayer(BanUtils.formatBannedMessage(ban)); sender.sendMessage("You have banned player " + playerName + " temporarely for " + Strings.join(reason, " ")); } @SubCommand(description = "Removes ban") public void remove(final Player sender, final String playerName) { sender.sendMessage("You cannot unban players at this moment. Please wait for developer, to implment unbans."); } }
2,159
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
GateCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/GateCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * Class used for /gate commands. * * @author Mato Kormuth * */ public class GateCommand implements CommandExecutor { private final WorldEditPlugin we; public GateCommand() { this.we = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin( "WorldEdit"); } @Override public boolean onCommand(final CommandSender sender, final Command command, final String paramString, final String[] args) { if (command.getName().equalsIgnoreCase("gate")) { if (sender instanceof Player) { if (sender.isOp()) { this.processOpCommand((Player) sender, args); } else { this.processCommand((Player) sender, args); } } else { sender.sendMessage(ChatManager.error("This command is only avaiable for players!")); } return true; } //sender.sendMessage(ChatFormat.error("Wrong use!")); return true; } private void processOpCommand(final Player sender, final String[] args) { if (args.length >= 2) { String action = args[0]; String name = args[1]; if (action.equalsIgnoreCase("create")) { if (args.length == 4) { //String actionType = args[2]; //String actionContent = args[3]; //if (actionType.equalsIgnoreCase("command")) //{ // actionContent = ""; // for (int i = 3; i < args.length; i++) // actionContent += args[i] + " "; //} if (this.checkSelection(sender)) { if (StorageEngine.getGate(name) == null) { sender.sendMessage(ChatManager.error("Can't configure gate!")); /* * StorageEngine.addGate(name, new TeleportGate( new Region(this.we.getSelection(sender)), * actionType, actionContent)); sender.sendMessage(ChatFormat.success("Gate '" + name + * "' has been created!")); */ } else { sender.sendMessage(ChatManager.error("Gate with name '" + name + "' already exists!")); } } } else { sender.sendMessage(ChatManager.error("Wrong use! Type /gate to help!")); } } else if (action.equalsIgnoreCase("modify")) { if (args.length == 4) { //String actionType = args[2]; //String actionContent = args[3]; if (StorageEngine.getGate(name) != null) { sender.sendMessage(ChatManager.error("Can't configure gate by command in this build.")); /* * StorageEngine.getGate(name).setType(actionType); * StorageEngine.getGate(name).setContent(actionContent); * sender.sendMessage(ChatFormat.success("Gate '" + name + "' has been modified!")); */ } else { sender.sendMessage(ChatManager.error("Gate with name '" + name + "' does not exists!")); } } else { sender.sendMessage(ChatManager.error("Wrong use! Type /gate to help!")); } } else if (action.equalsIgnoreCase("remove")) { if (StorageEngine.getGate(name) != null) { StorageEngine.removeGate(name); sender.sendMessage(ChatManager.success("Gate '" + name + "' has been removed!")); } else { sender.sendMessage(ChatManager.error("Gate '" + name + "' not found!")); } } else { sender.sendMessage(ChatManager.error("Invalid action!")); } } else { sender.sendMessage(ChatColor.RED + "/gate create <name> <actionType> <actionContent>"); sender.sendMessage(ChatColor.RED + "/gate modify <name> <actionType> <actionContent>"); sender.sendMessage(ChatColor.RED + "/gate remove <name>"); sender.sendMessage(ChatColor.LIGHT_PURPLE + "--------------------------------------"); sender.sendMessage(ChatColor.GREEN + "====== ACTION TYPES ======"); sender.sendMessage(ChatColor.GOLD + "Type: commmand"); sender.sendMessage(ChatColor.YELLOW + "Executes command as player. You can use %player% in content - it will be replaced with his name."); sender.sendMessage(ChatColor.BLUE + "Example: /gate create <name> command \"server staving\""); sender.sendMessage(ChatColor.GOLD + "Type: teleport"); sender.sendMessage(ChatColor.YELLOW + "Teleports player to specified location. Use syntax 'x,y,z,yaw,pitch,world'"); sender.sendMessage(ChatColor.BLUE + "Example: /gate create <name> teleport 15,85,41,0,90,world"); } } private void processCommand(final Player sender, final String[] args) { sender.sendMessage(ChatManager.error("Permission denied!")); } private boolean checkSelection(final Player sender) { if (this.we.getSelection(sender) != null) return true; else { sender.sendMessage(ChatManager.error("Make a WorldEdit selection first!")); return true; } } }
7,444
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PartyCommand.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/commands/PartyCommand.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.commands; import org.bukkit.Bukkit; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import eu.matejkormuth.pexel.PexelCore.chat.ChatManager; import eu.matejkormuth.pexel.PexelCore.core.Party; import eu.matejkormuth.pexel.PexelCore.core.StorageEngine; /** * Command party. * * @author Mato Kormuth * */ @CommandHandler(name = "party", aliases = { "partyy", "partyyy" }, description = "Command used to deal with parties") public class PartyCommand implements CommandExecutor { @Override public boolean onCommand(final CommandSender sender, final org.bukkit.command.Command command, final String arg2, final String[] args) { return true; } @SubCommand public void main(final Player sender) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() == null) { sender.sendMessage(ChatManager.error("You are not in party!")); } else { Party p = StorageEngine.getProfile(sender.getUniqueId()).getParty(); String players = ""; for (Player player : p.getPlayers()) players += player.getName() + ", "; players = players.substring(0, players.length() - 2); sender.sendMessage(ChatManager.success("You are in party with: " + players)); sender.sendMessage(ChatManager.success("Type /party leave to leave party.")); } } @SubCommand(name = "create", description = "Creates a new party") public void create(final Player sender) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() == null) { StorageEngine.getProfile(sender.getUniqueId()).setParty(new Party(sender)); StorageEngine.getProfile(sender.getUniqueId()).getParty().addPlayer(sender); } else { sender.sendMessage(ChatManager.error("You have to create party first! Type /party create!")); } } @SubCommand(name = "invite", description = "Invites player to your party") public void add(final Player sender, final String playerName) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() != null) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty().isOwner(sender)) { Player player = this.findPlayer(playerName); if (player != null) { if (StorageEngine.getProfile(player.getUniqueId()).getParty() == null) { sender.sendMessage(ChatManager.success("Adding player " + player.getDisplayName() + " to party!")); StorageEngine.getProfile(sender.getUniqueId()).getParty().addPlayer( player); StorageEngine.getProfile(player.getUniqueId()).setParty( StorageEngine.getProfile(sender.getUniqueId()).getParty()); } else { sender.sendMessage(ChatManager.error("Specified player is in another party!")); } } else { sender.sendMessage(ChatManager.error("Player not found!")); } } else { sender.sendMessage(ChatManager.error("Only party owner can invite players.")); } } else { this.create(sender); this.add(sender, playerName); } } @SubCommand(name = "kick", description = "Kicks player from your party") public void kick(final Player sender, final String playerName) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() != null) { Party p = StorageEngine.getProfile(sender.getUniqueId()).getParty(); if (p.isOwner(sender)) { Player player = this.findPlayer(playerName); if (player != null) { if (p.contains(player)) { player.sendMessage(ChatManager.success("You have been kicked from the party!")); sender.sendMessage(ChatManager.success("Player " + player.getName() + " has been kicked!")); p.removePlayer(player); } else { sender.sendMessage(ChatManager.error("Player not found in this party!")); } } else { sender.sendMessage(ChatManager.error("Player not found!")); } } else { sender.sendMessage(ChatManager.error("You are not owner of this party!")); } } else { sender.sendMessage(ChatManager.error("You are not in party!")); } } @SubCommand(name = "leave", description = "Leaves current party") public void leave(final Player sender) { if (StorageEngine.getProfile(sender.getUniqueId()).getParty() != null) { Party party = StorageEngine.getProfile(sender.getUniqueId()).getParty(); party.removePlayer(sender); sender.sendMessage(ChatManager.success("You have left party!")); } else { sender.sendMessage(ChatManager.error("You are not in party!")); } } private Player findPlayer(final String name) { for (Player p : Bukkit.getOnlinePlayers()) if (p.getName().equalsIgnoreCase(name)) return p; return null; } }
6,535
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BanStorage.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/BanStorage.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.UUID; import org.bukkit.entity.Player; /** * Class used as ban storage. */ public class BanStorage { private final HashMap<UUID, List<PlayerBan>> activeBans = new HashMap<UUID, List<PlayerBan>>(); private final HashMap<UUID, List<PlayerBan>> historyBans = new HashMap<UUID, List<PlayerBan>>(); public void addBan(final PlayerBan ban) { if (this.activeBans.containsKey(ban.uuid)) { this.activeBans.get(ban.uuid).add(ban); } else { this.activeBans.put(ban.uuid, new ArrayList<PlayerBan>()); this.activeBans.get(ban.uuid).add(ban); } } /** * Return if is player banned on specified part. * * @param player * player * @param part * bannable part * @return true or false */ public boolean isBanned(final Player player, final Bannable part) { if (!this.activeBans.containsKey(player.getUniqueId())) { return false; } else { for (Iterator<PlayerBan> iterator = this.activeBans.get(player.getUniqueId()).iterator(); iterator.hasNext();) { PlayerBan ban = iterator.next(); if (ban.getPart() == part) if (ban.isPermanent()) { return true; } else { if (ban.getExpirationTime() < System.currentTimeMillis()) { if (this.historyBans.containsKey(player.getUniqueId())) { this.historyBans.get(player.getUniqueId()).add(ban); } else { this.historyBans.put(player.getUniqueId(), new ArrayList<PlayerBan>()); this.historyBans.get(player.getUniqueId()).add(ban); } iterator.remove(); return false; } else { return true; } } } return false; } } /** * Returns ban or null. * * @param player * specified player * @param part * specified part * @return ban or null */ public PlayerBan getBan(final Player player, final Bannable part) { if (!this.activeBans.containsKey(player.getUniqueId())) { return null; } else { for (PlayerBan ban : this.activeBans.get(player.getUniqueId())) { if (ban.getPart() == part) return ban; } return null; } } /** * Retruns list of active bans by specified player. * * @param player * specififed player. * @return list of player's bans */ public List<PlayerBan> getActiveBans(final Player player) { return this.activeBans.get(player.getUniqueId()); } /** * Retruns list of past bans by specified player. * * @param player * specififed player. * @return list of player's bans */ public List<PlayerBan> getPastBans(final Player player) { return this.historyBans.get(player.getUniqueId()); } public void save() { } public void load() { } public List<PlayerBan> getBans() { List<PlayerBan> fullbans = new ArrayList<PlayerBan>(); for (List<PlayerBan> bans : this.activeBans.values()) fullbans.addAll(bans); return fullbans; } }
4,763
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Ban.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/Ban.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; import org.bukkit.entity.Player; /** * Interface that specified ban. */ public interface Ban { /** * Returns whether is ban permanent or not. * * @return true if ban is permanent, false otherwise. */ public boolean isPermanent(); /** * Returns author of ban. * * @return author of ban. */ public BanAuthor getAuthor(); /** * Return banned player. * * @return banned player. */ public Player getPlayer(); /** * Returns part of network, from which is player banned. * * @return part of network. */ public Bannable getPart(); /** * Returns reason of this ban. * * @return reson of ban. */ public String getReason(); /** * Returns length of ban in miliseconds if is ban temporary, -1 if is ban permanent. * * @return lenght in ms or -1. */ public long getLength(); /** * Returns creation time of ban in epoch time format or -1, if is ban permanent. * * @return timestamp of time at creation. */ public long getCreated(); /** * Returns time, when ban expiries or -1, if is ban permanent. * * @return epoch timestamp */ public long getExpirationTime(); }
2,191
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BanAuthor.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/BanAuthor.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; /** * Interface that specifies ban author. */ public interface BanAuthor { /** * Returns name of author of ban. * * @return name of author */ public String getName(); }
1,072
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BanUtils.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/BanUtils.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; import java.text.SimpleDateFormat; import java.util.Date; public class BanUtils { private static final SimpleDateFormat format = new SimpleDateFormat( "yyyy 'years', MM 'moths', dd 'days' 'and' HH 'hours', mm 'minutes', ss 'seconds'"); public static final String formatBannedMessage(final PlayerBan ban) { if (ban.isPermanent()) { return "You have been banned from " + ban.getPart().getBannableName() + " permanently!"; } else { return "You have been banned from " + ban.getPart().getBannableName() + " for " + format.format(new Date(ban.getLength())) + "!"; } } }
1,608
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
NamedBanAuthor.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/NamedBanAuthor.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; public class NamedBanAuthor implements BanAuthor { private final String name; public NamedBanAuthor(final String authorName) { this.name = authorName; } @Override public String getName() { return this.name; } }
1,133
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PlayerBan.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/PlayerBan.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; import java.util.UUID; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; import org.bukkit.Bukkit; import org.bukkit.entity.Player; /** * Basic Ban implementation. */ @XmlType(name = "playerBan") @XmlAccessorType(XmlAccessType.FIELD) public class PlayerBan implements Ban { // Lenght of ban in miliseconds, -1 means permanent. protected long length = -1; /** * Reason of ban. */ protected String reason; protected BanAuthor author; protected long creationTime; protected UUID uuid; // Just for caching name. protected String playerName; protected Bannable bannable; /** * Creates PERMANENT ban. * * @param reason * reason of ban * @param author * author of ban * @param player * player * @param bannable * banned part */ public PlayerBan(final String reason, final BanAuthor author, final Player player, final Bannable bannable) { this(-1, reason, author, System.currentTimeMillis(), player.getUniqueId(), player.getName(), bannable); } /** * Creates TEMPORARY ban. * * @param length * length of ban in miliseconds. */ public PlayerBan(final long length, final String reason, final BanAuthor author, final Player player, final Bannable bannable) { this(length, reason, author, System.currentTimeMillis(), player.getUniqueId(), player.getName(), bannable); } public PlayerBan(final long length, final String reason, final BanAuthor author, final long creationTime, final UUID uuid, final String playerName, final Bannable bannable) { this.length = length; this.reason = reason; this.author = author; this.creationTime = creationTime; this.uuid = uuid; this.playerName = playerName; this.bannable = bannable; } @Override public boolean isPermanent() { return this.length == -1; } @Override public BanAuthor getAuthor() { return this.author; } @Override public Player getPlayer() { return Bukkit.getPlayer(this.uuid); } @Override public Bannable getPart() { return this.bannable; } @Override public String getReason() { return this.reason; } @Override public long getLength() { return this.length; } @Override public long getCreated() { return this.creationTime; } @Override public long getExpirationTime() { return this.creationTime + this.length; } @Override public String toString() { return "BanBase{creationTime:" + this.creationTime + ", length:" + this.length + ", reason:" + this.reason + ", author:" + this.author.getName() + ", BID:" + this.bannable.getBannableName() + ", BN:" + this.bannable.getBannableName() + ", uuid:" + this.uuid + "}"; } public String getPlayerName() { return this.playerName; } }
4,181
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BanListServer.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/BanListServer.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpServer; import eu.matejkormuth.pexel.PexelCore.Pexel; import eu.matejkormuth.pexel.PexelCore.core.Log; public class BanListServer { HttpServer server; public BanListServer() { new Thread(new Runnable() { @Override public void run() { Log.info("Starting BAN-Server..."); try { BanListServer.this.server = HttpServer.create(new InetSocketAddress( 45198), 20); BanListServer.this.server.createContext("/bans", new BanListHandler()); BanListServer.this.server.setExecutor(null); BanListServer.this.server.start(); } catch (IOException e) { e.printStackTrace(); } Log.info("Stopping BAN-Server!"); } }).start(); } public void stop() { Log.info("Stopping BAN-SERVER..."); this.server.stop(0); } public class BanListHandler implements HttpHandler { @Override public void handle(final HttpExchange t) throws IOException { String response = "<html><body><h1>Banlist</h1>"; response += "<table><thead><tr><th>Player name</th><th>Created at</th><th>Expire at</th><th>Reason</th><th>Admin's name</th><th>Part</th></tr></thead><tbody>"; for (PlayerBan ban : Pexel.getBans().getBans()) { response += "<td>" + ban.getPlayerName() + "</td><td>" + ban.getCreated() + "</td><td>" + ban.getExpirationTime() + "</td><td>" + ban.getReason() + "</td><td>" + ban.getAuthor().getName() + "</td><td>" + ban.getPart().getBannableName() + "</pre>"; } response += "</tbody></table></body></html>"; t.sendResponseHeaders(200, response.length()); OutputStream os = t.getResponseBody(); os.write(response.getBytes()); os.close(); } } }
3,215
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
Bannable.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/bans/Bannable.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.bans; /** * Represents part of network, from which can be player banned. */ public interface Bannable { /** * Name of the bannable part. * * @return name of part. */ public String getBannableName(); /** * Returns ID of bannable part. * * @return id of part. */ public String getBannableID(); }
1,225
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
PHPStatsClient.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/stats/PHPStatsClient.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.stats; import java.io.DataOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; /** * PHP klient pre StatsClient. * * @author Mato Kormuth * */ public class PHPStatsClient extends StatsClient { //kluc a server private final String apiKey; private final String server; /** * Creates new instance of stats client. Connects to specified stats server with specified api key. * * @param apiKey * secret api key. * @param server * server path. */ public PHPStatsClient(final String apiKey, final String server) { this.server = server; this.apiKey = apiKey; } @Override public void setStat(final String pid, final String stat, final int value) { this.sendRequestAsync("setStat", "pid=" + pid + "&stat=" + stat + "&value=" + value); } @Override public void incrementStat(final String pid, final String stat, final int amount) { this.sendRequestAsync("incrementStat", "pid=" + pid + "&stat=" + stat + "&amount=" + amount); } @Override public void decrementStat(final String pid, final String stat, final int amount) { this.sendRequestAsync("decrementStat", "pid=" + pid + "&stat=" + stat + "&amount=" + amount); } @Override public void resetStats(final String pid) { this.sendRequestAsync("resetStats", "pid=" + pid); } @Override public void registerUser(final String pid, final String name, final String email) { this.sendRequestAsync("registerUser", "pid=" + pid + "&name=" + name + "&email=" + email); } private void sendRequestAsync(final String action, final String params) { try { HttpURLConnection connection = (HttpURLConnection) new URL(this.server + "/api.php").openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes("apikey=" + this.apiKey + "&action=" + action + "&" + params); wr.flush(); wr.close(); } catch (IOException e) { e.printStackTrace(); } } }
3,239
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
StatsClient.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/stats/StatsClient.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.stats; /** * Java interface for mertex statistics. (stats.mertex.eu) * * @author Mato Kormuth * * @see StatsClient#setStat(String, String, int) * @see StatsClient#setAchievement(String, String) * @see StatsClient#incrementStat(String, String) */ public abstract class StatsClient { //Dokonci. /** * Adds flag for specified player for specified achievement. * * @param pid * player id * @param achievement * achievement id */ public void setAchievement(final String pid, final String achievement) { this.setStat(pid, "achievement." + achievement, 1); } /** * Sets stat of player to zero. * * @param pid * player id * @param stat * statistic id */ public void resetStat(final String pid, final String stat) { this.setStat(pid, stat, 0); } /** * Increments player's stat by one. * * @param pid * player id * @param stat * statistic id */ public void incrementStat(final String pid, final String stat) { this.incrementStat(pid, stat, 1); } /** * Decrements player's stat by one. * * @param pid * player id * @param stat * statistic id */ public void decrementStat(final String pid, final String stat) { this.decrementStat(pid, stat, 1); } /** * Sets player's stat to specified value. * * @param pid * player id * @param stat * static id * @param value * value of stat to be set */ public abstract void setStat(final String pid, final String stat, final int value); /** * Increments player's stat by one. * * @param pid * player id * @param stat * statistic id * @param amount * amount to increment */ public abstract void incrementStat(final String pid, final String stat, final int amount); /** * Decrements player's stat by one. * * @param pid * player id * @param stat * statistic id * @param amount * amount to decrement */ public abstract void decrementStat(final String pid, final String stat, final int amount); /** * Sets all stats of specified player to zero. * * @param pid * player id */ public abstract void resetStats(final String pid); /** * Registers new user or loads his info. * * @param pid * player id * @param name * player name * @param email * player's email */ public abstract void registerUser(final String pid, final String name, final String email); }
3,835
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
ItemUtils.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/util/ItemUtils.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.util; import java.util.List; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.material.MaterialData; /** * Class that contains many useful functions for working with InventoryMenus. * * @author Mato Kormuth * */ public class ItemUtils { public static ItemStack itemStack(final Material material, final int amount, final byte data, final short damage, final String displayName, final List<String> lore) { @SuppressWarnings("deprecation") ItemStack is = new ItemStack(material, amount, damage, data); ItemMeta im = is.getItemMeta(); if (im != null) im.setDisplayName(displayName); if (lore != null) im.setLore(lore); is.setItemMeta(im); return is; } public static ItemStack itemStack(final Material material, final int amount, final String displayName, final List<String> lore) { ItemStack is = new ItemStack(material, amount); ItemMeta im = is.getItemMeta(); if (im != null) im.setDisplayName(displayName); if (lore != null) im.setLore(lore); is.setItemMeta(im); return is; } /** * Just a utility, that returns names item stack with amount of 1. * * <code><br><br> * ItemStack is = new ItemStack(material);<br> * ItemMeta im = is.getItemMeta();<br> * if (im != null)<br> * im.setDisplayName(displayName);<br> * if (lore != null)<br> * im.setLore(lore);<br> * is.setItemMeta(im);<br> * return is;<br> * </code> * * @param material * @param displayName * @param lore * @return */ public static ItemStack namedItemStack(final Material material, final String displayName, final List<String> lore) { ItemStack is = new ItemStack(material); ItemMeta im = is.getItemMeta(); if (im != null) im.setDisplayName(displayName); if (lore != null) im.setLore(lore); is.setItemMeta(im); return is; } /** * Returns specified colored lether armor. * * @param material * @param color * @return */ public static ItemStack coloredLetherArmor(final Material material, final Color color) { ItemStack larmor = new ItemStack(material, 1); LeatherArmorMeta lam = (LeatherArmorMeta) larmor.getItemMeta(); lam.setColor(color); larmor.setItemMeta(lam); return larmor; } public static ItemStack skull(final String name) { ItemStack skull = new ItemStack(Material.SKULL_ITEM); SkullMeta meta = (SkullMeta) skull.getItemMeta(); meta.setOwner(name); skull.setItemMeta(meta); return skull; } public static Builder builder(final Material material) { return new ItemUtils.Builder(material); } public static class Builder { private final ItemStack is; public Builder(final Material material) { this.is = new ItemStack(material); } public ItemStack build() { return this.is; } public Builder amount(final int amount) { this.is.setAmount(amount); return this; } public Builder durability(final short durability) { this.is.setDurability(durability); return this; } public Builder data(final MaterialData data) { this.is.setData(data); return this; } public Builder enchant(final Enchantment enchantment, final int level) { this.is.addEnchantment(enchantment, level); return this; } public Builder unsafeEnchant(final Enchantment enchantment, final int level) { this.is.addUnsafeEnchantment(enchantment, level); return this; } public Builder lore(final List<String> lore) { ItemMeta im = this.is.getItemMeta(); im.setLore(lore); this.is.setItemMeta(im); return this; } public Builder name(final String displayName) { ItemMeta im = this.is.getItemMeta(); im.setDisplayName(displayName); this.is.setItemMeta(im); return this; } } /** * Returns display name or null. * * @param weapon * @return display name or null */ public static String getDisplayName(final ItemStack weapon) { ItemMeta meta = weapon.getItemMeta(); return meta.getDisplayName(); } /** * @param weapon * @param laserPistol * @return */ public static boolean sameName(final ItemStack first, final ItemStack second) { return ItemUtils.getDisplayName(first).equals(ItemUtils.getDisplayName(second)); } }
6,114
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z
BlockIterator.java
/FileExtraction/Java_unseen/dobrakmato_PexelCore/src/eu/matejkormuth/pexel/PexelCore/util/BlockIterator.java
// @formatter:off /* * Pexel Project - Minecraft minigame server platform. * Copyright (C) 2014 Matej Kormuth <http://www.matejkormuth.eu> * * This file is part of Pexel. * * Pexel is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Pexel 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see * <http://www.gnu.org/licenses/>. * */ // @formatter:on package eu.matejkormuth.pexel.PexelCore.util; import java.util.Iterator; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; /** * Block iterator. */ public class BlockIterator implements Iterator<Block> { private final Location location; private int directionX; private int directionY; private int directionZ; /** * Creates new instance of <b>BlockIterator</b>. This class should be used for iterating over blocks in specified * direction and should not be used to detect block patterns. * * @param startBlock * @param direction */ public BlockIterator(final Block startBlock, final BlockFace direction) { this.location = startBlock.getLocation(); this.directionX = direction.getModX(); this.directionY = direction.getModY(); this.directionZ = direction.getModZ(); } public BlockIterator(final Block startBlock, final int modX, final int modY, final int modZ) { this.location = startBlock.getLocation(); this.directionX = modX; this.directionY = modY; this.directionZ = modZ; } @Override public boolean hasNext() { return true; } @Override public Block next() { return this.location.add(this.directionX, this.directionY, this.directionZ).getBlock(); } /** * Iterates by specified direction until specified material is detected. Then it returns first block, that is from * specififed material. * * @param specified * specified material * @return first block in specified direction of specified type */ public Block until(final Material specified) { do { return this.location.getBlock(); } while (this.next().getType() == specified); } @Override public void remove() { this.location.getBlock().setType(Material.AIR); } /** * @param direction * the direction to set */ public void setDirection(final BlockFace direction) { this.directionX = direction.getModX(); this.directionY = direction.getModY(); this.directionZ = direction.getModZ(); } public void setDirection(final int modX, final int modY, final int modZ) { this.directionX = modX; this.directionY = modY; this.directionZ = modZ; } }
3,348
Java
.java
dobrakmato/PexelCore
12
5
0
2014-08-28T19:30:48Z
2015-02-06T15:49:16Z