Restructures the plugin and starts work on cleaning and commenting the code
This commit is contained in:
parent
2480a432a4
commit
6ff998ac3b
14
README.md
14
README.md
@ -156,7 +156,7 @@ chargefreedestination - Enable to allow free travel from any gate to a free gate
|
|||||||
freegatesgreen - Enable to make gates that won't cost the player money show up as green
|
freegatesgreen - Enable to make gates that won't cost the player money show up as green
|
||||||
toowner - Whether the money from gate-use goes to the owner or nobody
|
toowner - Whether the money from gate-use goes to the owner or nobody
|
||||||
maxgates - If non-zero, will define the maximum amount of gates allowed on any network.
|
maxgates - If non-zero, will define the maximum amount of gates allowed on any network.
|
||||||
lang - The language to use (Included languages: en, de)
|
chosenLanguage - The language to use (Included languages: en, de)
|
||||||
destMemory - Whether to set the first destination as the last used destination for all gates
|
destMemory - Whether to set the first destination as the last used destination for all gates
|
||||||
ignoreEntrance - Set this option to true to not check the entrance of a gate on startup. This is a workaround for snowmen breaking gates.
|
ignoreEntrance - Set this option to true to not check the entrance of a gate on startup. This is a workaround for snowmen breaking gates.
|
||||||
handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates.
|
handleVehicles - Whether or not to handle vehicles going through gates. Set to false to disallow vehicles (Manned or not) going through gates.
|
||||||
@ -170,7 +170,7 @@ permdebug: Whether to show massive permission debug output
|
|||||||
```
|
```
|
||||||
|
|
||||||
# Message Customization
|
# Message Customization
|
||||||
It is possible to customize all of the messages Stargate displays, including the [Stargate] prefix. You can find the strings in plugins/Stargate/lang/en.txt.
|
It is possible to customize all of the messages Stargate displays, including the [Stargate] prefix. You can find the strings in plugins/Stargate/chosenLanguage/en.txt.
|
||||||
|
|
||||||
If a string is removed, or left blank, it will not be shown when the user does the action associated with it.
|
If a string is removed, or left blank, it will not be shown when the user does the action associated with it.
|
||||||
There are three special cases when it comes to messages, these are:
|
There are three special cases when it comes to messages, these are:
|
||||||
@ -211,7 +211,7 @@ createConflict=Gate conflicts with existing gate
|
|||||||
- Add custom buttons
|
- Add custom buttons
|
||||||
#### [Version 0.8.0.2] PseudoKnight fork
|
#### [Version 0.8.0.2] PseudoKnight fork
|
||||||
- Fix player relative yaw when exiting portal
|
- Fix player relative yaw when exiting portal
|
||||||
- Add color code support in lang files
|
- Add color code support in chosenLanguage files
|
||||||
#### [Version 0.8.0.1] PseudoKnight fork
|
#### [Version 0.8.0.1] PseudoKnight fork
|
||||||
- Fix slab check for portal exits
|
- Fix slab check for portal exits
|
||||||
- Improve material checks for gate configuration
|
- Improve material checks for gate configuration
|
||||||
@ -377,14 +377,14 @@ createConflict=Gate conflicts with existing gate
|
|||||||
#### [Version 0.6.10]
|
#### [Version 0.6.10]
|
||||||
- Added Register support as opposed to iConomy
|
- Added Register support as opposed to iConomy
|
||||||
#### [Version 0.6.9]
|
#### [Version 0.6.9]
|
||||||
- Added UTF8 support for lang files (With or without BOM)
|
- Added UTF8 support for chosenLanguage files (With or without BOM)
|
||||||
#### [Version 0.6.8]
|
#### [Version 0.6.8]
|
||||||
- Fixed unmanned carts losing velocity through gates
|
- Fixed unmanned carts losing velocity through gates
|
||||||
- /sg reload now properly switches languages
|
- /sg reload now properly switches languages
|
||||||
#### [Version 0.6.7]
|
#### [Version 0.6.7]
|
||||||
- Added lang option
|
- Added chosenLanguage option
|
||||||
- Removed language debug output
|
- Removed language debug output
|
||||||
- Added German language (lang=de) -- Thanks EduardBaer
|
- Added German language (chosenLanguage=de) -- Thanks EduardBaer
|
||||||
#### [Version 0.6.6]
|
#### [Version 0.6.6]
|
||||||
- Added %cost% and %portal% to all eco* messages
|
- Added %cost% and %portal% to all eco* messages
|
||||||
- Fixed an issue when creating a gate on a network you don't have access to
|
- Fixed an issue when creating a gate on a network you don't have access to
|
||||||
@ -560,6 +560,6 @@ createConflict=Gate conflicts with existing gate
|
|||||||
#### [Version 0.04]
|
#### [Version 0.04]
|
||||||
- Updated to multi-world Bukkit
|
- Updated to multi-world Bukkit
|
||||||
#### [Version 0.03]
|
#### [Version 0.03]
|
||||||
- Changed package to net.TheDgtl.*
|
- Changed package to net.knarcraft.*
|
||||||
- Everything now uses Blox instead of Block objects
|
- Everything now uses Blox instead of Block objects
|
||||||
- Started on vehicle code, but it's still buggy
|
- Started on vehicle code, but it's still buggy
|
||||||
|
37
pom.xml
37
pom.xml
@ -1,11 +1,23 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.TheDgtl</groupId>
|
|
||||||
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>Stargate</artifactId>
|
<artifactId>Stargate</artifactId>
|
||||||
<version>0.8.0.3</version>
|
<version>0.8.0.0</version>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU Lesser General Public License</name>
|
||||||
|
<url>https://www.gnu.org/licenses/lgpl-3.0.en.html</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>spigot-repo</id>
|
<id>spigot-repo</id>
|
||||||
@ -16,11 +28,12 @@
|
|||||||
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.16.2-R0.1-SNAPSHOT</version>
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.milkbowl.vault</groupId>
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
@ -28,23 +41,9 @@
|
|||||||
<version>1.7</version>
|
<version>1.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<targetPath>net/TheDgtl/Stargate/resources</targetPath>
|
|
||||||
<directory>src/net/TheDgtl/Stargate/resources</directory>
|
|
||||||
<includes>
|
|
||||||
<include>*.txt</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
<resource>
|
|
||||||
<directory>src</directory>
|
|
||||||
<includes>
|
|
||||||
<include>*.yml</include>
|
|
||||||
</includes>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
199
src/main/java/net/knarcraft/stargate/BlockLocation.java
Normal file
199
src/main/java/net/knarcraft/stargate/BlockLocation.java
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
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.block.data.BlockData;
|
||||||
|
import org.bukkit.block.data.type.Sign;
|
||||||
|
import org.bukkit.block.data.type.WallSign;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011 Shaun (sturmeh)
|
||||||
|
* Copyright (C) 2011 Dinnerbone
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a block location
|
||||||
|
*/
|
||||||
|
public class BlockLocation {
|
||||||
|
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int z;
|
||||||
|
private final World world;
|
||||||
|
private BlockLocation parent = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new block
|
||||||
|
* @param world <p>The world the block exists in</p>
|
||||||
|
* @param x <p>The x coordinate of the block</p>
|
||||||
|
* @param y <p>The y coordinate of the block</p>
|
||||||
|
* @param z <p>The z coordinate of the block</p>
|
||||||
|
*/
|
||||||
|
public BlockLocation(World world, int x, int y, int z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies a craftbukkit block
|
||||||
|
* @param block <p>The block to </p>
|
||||||
|
*/
|
||||||
|
public BlockLocation(Block block) {
|
||||||
|
this.x = block.getX();
|
||||||
|
this.y = block.getY();
|
||||||
|
this.z = block.getZ();
|
||||||
|
this.world = block.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new block from a location
|
||||||
|
* @param location <p>The location the block exists in</p>
|
||||||
|
*/
|
||||||
|
public BlockLocation(Location location) {
|
||||||
|
this.x = location.getBlockX();
|
||||||
|
this.y = location.getBlockY();
|
||||||
|
this.z = location.getBlockZ();
|
||||||
|
this.world = location.getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a block from a string
|
||||||
|
* @param world <p>The world the block exists in</p>
|
||||||
|
* @param string <p>A comma separated list of z, y and z coordinates as integers</p>
|
||||||
|
*/
|
||||||
|
public BlockLocation(World world, String string) {
|
||||||
|
String[] split = string.split(",");
|
||||||
|
this.x = Integer.parseInt(split[0]);
|
||||||
|
this.y = Integer.parseInt(split[1]);
|
||||||
|
this.z = Integer.parseInt(split[2]);
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a new block in a relative position to this block
|
||||||
|
* @param x <p>The x position relative to this block's position</p>
|
||||||
|
* @param y <p>The y position relative to this block's position</p>
|
||||||
|
* @param z <p>The z position relative to this block's position</p>
|
||||||
|
* @return <p>A new block </p>
|
||||||
|
*/
|
||||||
|
public BlockLocation makeRelative(int x, int y, int z) {
|
||||||
|
return new BlockLocation(this.world, this.x + x, this.y + y, this.z + z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location makeRelativeLoc(double x, double y, double z, float rotX, float rotY) {
|
||||||
|
return new Location(this.world, (double) this.x + x, (double) this.y + y, (double) this.z + z, rotX, rotY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockLocation modRelative(int right, int depth, int distance, int modX, int modY, int modZ) {
|
||||||
|
return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) {
|
||||||
|
return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Material type) {
|
||||||
|
world.getBlockAt(x, y, z).setType(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getType() {
|
||||||
|
return world.getBlockAt(x, y, z).getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getBlock() {
|
||||||
|
return world.getBlockAt(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return new Location(world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZ() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public World getWorld() {
|
||||||
|
return world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Block getParent() {
|
||||||
|
if (parent == null) findParent();
|
||||||
|
if (parent == null) return null;
|
||||||
|
return parent.getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void findParent() {
|
||||||
|
int offsetX = 0;
|
||||||
|
int offsetY = 0;
|
||||||
|
int offsetZ = 0;
|
||||||
|
|
||||||
|
BlockData blk = getBlock().getBlockData();
|
||||||
|
if (blk instanceof WallSign) {
|
||||||
|
BlockFace facing = ((WallSign) blk).getFacing().getOppositeFace();
|
||||||
|
offsetX = facing.getModX();
|
||||||
|
offsetZ = facing.getModZ();
|
||||||
|
} else if (blk instanceof Sign) {
|
||||||
|
offsetY = -1;
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
parent = new BlockLocation(world, getX() + offsetX, getY() + offsetY, getZ() + offsetZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(x) + ',' + y + ',' + z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = 18;
|
||||||
|
|
||||||
|
result = result * 27 + x;
|
||||||
|
result = result * 27 + y;
|
||||||
|
result = result * 27 + z;
|
||||||
|
result = result * 27 + world.getName().hashCode();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) return true;
|
||||||
|
if (obj == null) return false;
|
||||||
|
if (getClass() != obj.getClass()) return false;
|
||||||
|
|
||||||
|
BlockLocation blockLocation = (BlockLocation) obj;
|
||||||
|
return (x == blockLocation.x) && (y == blockLocation.y) && (z == blockLocation.z) && (world.getName().equals(blockLocation.world.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
48
src/main/java/net/knarcraft/stargate/BloxPopulator.java
Normal file
48
src/main/java/net/knarcraft/stargate/BloxPopulator.java
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import org.bukkit.Axis;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
|
||||||
|
public class BloxPopulator {
|
||||||
|
|
||||||
|
private BlockLocation blockLocation;
|
||||||
|
private Material nextMat;
|
||||||
|
private Axis nextAxis;
|
||||||
|
|
||||||
|
public BloxPopulator(BlockLocation b, Material m) {
|
||||||
|
blockLocation = b;
|
||||||
|
nextMat = m;
|
||||||
|
nextAxis = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BloxPopulator(BlockLocation b, Material m, Axis a) {
|
||||||
|
blockLocation = b;
|
||||||
|
nextMat = m;
|
||||||
|
nextAxis = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBlockLocation(BlockLocation b) {
|
||||||
|
blockLocation = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMat(Material m) {
|
||||||
|
nextMat = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAxis(Axis a) {
|
||||||
|
nextAxis = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockLocation getBlockLocation() {
|
||||||
|
return blockLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getMat() {
|
||||||
|
return nextMat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Axis getAxis() {
|
||||||
|
return nextAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class BungeeCoordListener implements PluginMessageListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, Player unused, byte[] message) {
|
||||||
|
if (!Stargate.enableBungee || !channel.equals("BungeeCord")) return;
|
||||||
|
|
||||||
|
// Get data from message
|
||||||
|
String inChannel;
|
||||||
|
byte[] data;
|
||||||
|
try {
|
||||||
|
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
|
||||||
|
inChannel = in.readUTF();
|
||||||
|
short len = in.readShort();
|
||||||
|
data = new byte[len];
|
||||||
|
in.readFully(data);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Stargate.log.severe("[stargate] Error receiving BungeeCord message");
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that it's an SGBungee packet
|
||||||
|
if (!inChannel.equals("SGBungee")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data should be player name, and destination gate name
|
||||||
|
String msg = new String(data);
|
||||||
|
String[] parts = msg.split("#@#");
|
||||||
|
|
||||||
|
String playerName = parts[0];
|
||||||
|
String destination = parts[1];
|
||||||
|
|
||||||
|
// Check if the player is online, if so, teleport, otherwise, queue
|
||||||
|
Player player = Stargate.server.getPlayer(playerName);
|
||||||
|
if (player == null) {
|
||||||
|
Stargate.bungeeQueue.put(playerName.toLowerCase(), destination);
|
||||||
|
} else {
|
||||||
|
Portal dest = Portal.getBungeeGate(destination);
|
||||||
|
// Specified an invalid gate. For now we'll just let them connect at their current location
|
||||||
|
if (dest == null) {
|
||||||
|
Stargate.log.info("[stargate] Bungee gate " + destination + " does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dest.teleport(player, dest, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
src/main/java/net/knarcraft/stargate/CommonFunctions.java
Normal file
43
src/main/java/net/knarcraft/stargate/CommonFunctions.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A holding class for methods shared between classes
|
||||||
|
*
|
||||||
|
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
||||||
|
*/
|
||||||
|
public final class CommonFunctions {
|
||||||
|
|
||||||
|
private CommonFunctions() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a resource as an InputStream
|
||||||
|
*
|
||||||
|
* @param resourceName <p>The name of the resource you want to readFromServer</p>
|
||||||
|
* @return <p>An input stream which can be used to access the resource</p>
|
||||||
|
*/
|
||||||
|
public static InputStream getResourceAsStream(String resourceName) {
|
||||||
|
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||||
|
return classloader.getResourceAsStream(resourceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
106
src/main/java/net/knarcraft/stargate/EconomyHandler.java
Normal file
106
src/main/java/net/knarcraft/stargate/EconomyHandler.java
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class EconomyHandler {
|
||||||
|
public static boolean economyEnabled = false;
|
||||||
|
public static Economy economy = null;
|
||||||
|
public static Plugin vault = null;
|
||||||
|
|
||||||
|
public static int useCost = 0;
|
||||||
|
public static int createCost = 0;
|
||||||
|
public static int destroyCost = 0;
|
||||||
|
public static boolean toOwner = false;
|
||||||
|
public static boolean chargeFreeDestination = true;
|
||||||
|
public static boolean freeGatesGreen = false;
|
||||||
|
|
||||||
|
public static double getBalance(Player player) {
|
||||||
|
if (!economyEnabled) return 0;
|
||||||
|
return economy.getBalance(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean chargePlayer(Player player, String target, double amount) {
|
||||||
|
if (!economyEnabled) return true;
|
||||||
|
if (player.getName().equals(target)) return true;
|
||||||
|
if (economy != null) {
|
||||||
|
if (!economy.has(player, amount)) return false;
|
||||||
|
economy.withdrawPlayer(player, amount);
|
||||||
|
economy.depositPlayer(target, amount);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean chargePlayer(Player player, UUID target, double amount) {
|
||||||
|
if (!economyEnabled) return true;
|
||||||
|
if (player.getUniqueId().compareTo(target) == 0) return true;
|
||||||
|
if (economy != null) {
|
||||||
|
if (!economy.has(player, amount)) return false;
|
||||||
|
economy.withdrawPlayer(player, amount);
|
||||||
|
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean chargePlayer(Player player, double amount) {
|
||||||
|
if (!economyEnabled) return true;
|
||||||
|
if (economy != null) {
|
||||||
|
if (!economy.has(player, amount)) return false;
|
||||||
|
economy.withdrawPlayer(player, amount);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String format(int amt) {
|
||||||
|
if (economyEnabled) {
|
||||||
|
return economy.format(amt);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean setupEconomy(PluginManager pm) {
|
||||||
|
if (!economyEnabled) return false;
|
||||||
|
// Check for Vault
|
||||||
|
Plugin p = pm.getPlugin("Vault");
|
||||||
|
if (p != null && p.isEnabled()) {
|
||||||
|
RegisteredServiceProvider<Economy> economyProvider = Stargate.server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||||
|
if (economyProvider != null) {
|
||||||
|
economy = economyProvider.getProvider();
|
||||||
|
vault = p;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
economyEnabled = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean useEconomy() {
|
||||||
|
return economyEnabled && economy != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
516
src/main/java/net/knarcraft/stargate/Gate.java
Normal file
516
src/main/java/net/knarcraft/stargate/Gate.java
Normal file
@ -0,0 +1,516 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Tag;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011 Shaun (sturmeh)
|
||||||
|
* Copyright (C) 2011 Dinnerbone
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class Gate {
|
||||||
|
|
||||||
|
private static final Character ANYTHING = ' ';
|
||||||
|
private static final Character ENTRANCE = '.';
|
||||||
|
private static final Character EXIT = '*';
|
||||||
|
private static final HashMap<String, Gate> gates = new HashMap<>();
|
||||||
|
private static final HashMap<Material, ArrayList<Gate>> controlBlocks = new HashMap<>();
|
||||||
|
private static final HashSet<Material> frameBlocks = new HashSet<>();
|
||||||
|
|
||||||
|
private final String filename;
|
||||||
|
private final Character[][] layout;
|
||||||
|
private final HashMap<Character, Material> types;
|
||||||
|
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
||||||
|
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
||||||
|
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
||||||
|
private RelativeBlockVector exitBlock = null;
|
||||||
|
private final HashMap<RelativeBlockVector, Integer> exits = new HashMap<>();
|
||||||
|
private Material portalBlockOpen = Material.NETHER_PORTAL;
|
||||||
|
private Material portalBlockClosed = Material.AIR;
|
||||||
|
private Material button = Material.STONE_BUTTON;
|
||||||
|
|
||||||
|
// Economy information
|
||||||
|
private int useCost = -1;
|
||||||
|
private int createCost = -1;
|
||||||
|
private int destroyCost = -1;
|
||||||
|
private boolean toOwner = false;
|
||||||
|
|
||||||
|
public Gate(String filename, Character[][] layout, HashMap<Character, Material> types) {
|
||||||
|
this.filename = filename;
|
||||||
|
this.layout = layout;
|
||||||
|
this.types = types;
|
||||||
|
|
||||||
|
populateCoordinates();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populateCoordinates() {
|
||||||
|
ArrayList<RelativeBlockVector> entranceList = new ArrayList<>();
|
||||||
|
ArrayList<RelativeBlockVector> borderList = new ArrayList<>();
|
||||||
|
ArrayList<RelativeBlockVector> controlList = new ArrayList<>();
|
||||||
|
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
||||||
|
int[] exitDepths = new int[layout[0].length];
|
||||||
|
RelativeBlockVector lastExit = null;
|
||||||
|
|
||||||
|
for (int y = 0; y < layout.length; y++) {
|
||||||
|
for (int x = 0; x < layout[y].length; x++) {
|
||||||
|
Character key = layout[y][x];
|
||||||
|
if (key.equals('-')) {
|
||||||
|
controlList.add(new RelativeBlockVector(x, y, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.equals(ENTRANCE) || key.equals(EXIT)) {
|
||||||
|
entranceList.add(new RelativeBlockVector(x, y, 0));
|
||||||
|
exitDepths[x] = y;
|
||||||
|
if (key.equals(EXIT)) {
|
||||||
|
this.exitBlock = new RelativeBlockVector(x, y, 0);
|
||||||
|
}
|
||||||
|
} else if (!key.equals(ANYTHING)) {
|
||||||
|
borderList.add(new RelativeBlockVector(x, y, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 0; x < exitDepths.length; x++) {
|
||||||
|
relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = relativeExits.length - 1; x >= 0; x--) {
|
||||||
|
if (relativeExits[x] != null) {
|
||||||
|
lastExit = relativeExits[x];
|
||||||
|
} else {
|
||||||
|
relativeExits[x] = lastExit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.entrances = entranceList.toArray(this.entrances);
|
||||||
|
this.border = borderList.toArray(this.border);
|
||||||
|
this.controls = controlList.toArray(this.controls);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(String gateFolder) {
|
||||||
|
try {
|
||||||
|
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
|
||||||
|
|
||||||
|
writeConfig(bw, "portal-open", portalBlockOpen.name());
|
||||||
|
writeConfig(bw, "portal-closed", portalBlockClosed.name());
|
||||||
|
writeConfig(bw, "button", button.name());
|
||||||
|
if (useCost != -1)
|
||||||
|
writeConfig(bw, "usecost", useCost);
|
||||||
|
if (createCost != -1)
|
||||||
|
writeConfig(bw, "createcost", createCost);
|
||||||
|
if (destroyCost != -1)
|
||||||
|
writeConfig(bw, "destroycost", destroyCost);
|
||||||
|
writeConfig(bw, "toowner", toOwner);
|
||||||
|
|
||||||
|
for (Map.Entry<Character, Material> entry : types.entrySet()) {
|
||||||
|
Character type = entry.getKey();
|
||||||
|
Material value = entry.getValue();
|
||||||
|
// Skip control values
|
||||||
|
if (type.equals(ANYTHING) || type.equals(ENTRANCE) || type.equals(EXIT)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
bw.append(type);
|
||||||
|
bw.append('=');
|
||||||
|
if (value != null) {
|
||||||
|
bw.append(value.toString());
|
||||||
|
}
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
bw.newLine();
|
||||||
|
|
||||||
|
for (Character[] aLayout : layout) {
|
||||||
|
for (Character symbol : aLayout) {
|
||||||
|
bw.append(symbol);
|
||||||
|
}
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
bw.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
|
||||||
|
bw.append(String.format("%s=%d", key, value));
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException {
|
||||||
|
bw.append(String.format("%s=%b", key, value));
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeConfig(BufferedWriter bw, String key, String value) throws IOException {
|
||||||
|
bw.append(String.format("%s=%s", key, value));
|
||||||
|
bw.newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Character[][] getLayout() {
|
||||||
|
return layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<Character, Material> getTypes() {
|
||||||
|
return types;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeBlockVector[] getEntrances() {
|
||||||
|
return entrances;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeBlockVector[] getBorder() {
|
||||||
|
return border;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeBlockVector[] getControls() {
|
||||||
|
return controls;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<RelativeBlockVector, Integer> getExits() {
|
||||||
|
return exits;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RelativeBlockVector getExit() {
|
||||||
|
return exitBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getControlBlock() {
|
||||||
|
return types.get('-');
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilename() {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getPortalBlockOpen() {
|
||||||
|
return portalBlockOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPortalBlockOpen(Material type) {
|
||||||
|
portalBlockOpen = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getPortalBlockClosed() {
|
||||||
|
return portalBlockClosed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPortalBlockClosed(Material type) {
|
||||||
|
portalBlockClosed = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Material getButton() {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUseCost() {
|
||||||
|
if (useCost < 0) return EconomyHandler.useCost;
|
||||||
|
return useCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCreateCost() {
|
||||||
|
if (createCost < 0) return EconomyHandler.createCost;
|
||||||
|
return createCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDestroyCost() {
|
||||||
|
if (destroyCost < 0) return EconomyHandler.destroyCost;
|
||||||
|
return destroyCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getToOwner() {
|
||||||
|
return toOwner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(BlockLocation topleft, int modX, int modZ) {
|
||||||
|
return matches(topleft, modX, modZ, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(BlockLocation topleft, int modX, int modZ, boolean onCreate) {
|
||||||
|
HashMap<Character, Material> portalTypes = new HashMap<>(types);
|
||||||
|
for (int y = 0; y < layout.length; y++) {
|
||||||
|
for (int x = 0; x < layout[y].length; x++) {
|
||||||
|
Character key = layout[y][x];
|
||||||
|
|
||||||
|
if (key.equals(ENTRANCE) || key.equals(EXIT)) {
|
||||||
|
if (Stargate.ignoreEntrance) continue;
|
||||||
|
|
||||||
|
Material type = topleft.modRelative(x, y, 0, modX, 1, modZ).getType();
|
||||||
|
|
||||||
|
// Ignore entrance if it's air and we're creating a new gate
|
||||||
|
if (onCreate && type == Material.AIR) continue;
|
||||||
|
|
||||||
|
if (type != portalBlockClosed && type != portalBlockOpen) {
|
||||||
|
Stargate.debug("Gate::Matches", "Entrance/Exit Material Mismatch: " + type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!key.equals(ANYTHING)) {
|
||||||
|
Material id = portalTypes.get(key);
|
||||||
|
if (id == null) {
|
||||||
|
portalTypes.put(key, topleft.modRelative(x, y, 0, modX, 1, modZ).getType());
|
||||||
|
} else if (topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) {
|
||||||
|
Stargate.debug("Gate::Matches", "Block Type Mismatch: " + topleft.modRelative(x, y, 0, modX, 1, modZ).getType() + " != " + id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerGate(Gate gate) {
|
||||||
|
gates.put(gate.getFilename(), gate);
|
||||||
|
|
||||||
|
Material blockID = gate.getControlBlock();
|
||||||
|
|
||||||
|
if (!controlBlocks.containsKey(blockID)) {
|
||||||
|
controlBlocks.put(blockID, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
controlBlocks.get(blockID).add(gate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Gate loadGate(File file) {
|
||||||
|
Scanner scanner = null;
|
||||||
|
boolean designing = false;
|
||||||
|
ArrayList<ArrayList<Character>> design = new ArrayList<>();
|
||||||
|
HashMap<Character, Material> types = new HashMap<>();
|
||||||
|
HashMap<String, String> config = new HashMap<>();
|
||||||
|
HashSet<Material> frameTypes = new HashSet<>();
|
||||||
|
int cols = 0;
|
||||||
|
|
||||||
|
// Init types map
|
||||||
|
types.put(ENTRANCE, Material.AIR);
|
||||||
|
types.put(EXIT, Material.AIR);
|
||||||
|
types.put(ANYTHING, Material.AIR);
|
||||||
|
|
||||||
|
try {
|
||||||
|
scanner = new Scanner(file);
|
||||||
|
|
||||||
|
while (scanner.hasNextLine()) {
|
||||||
|
String line = scanner.nextLine();
|
||||||
|
|
||||||
|
if (designing) {
|
||||||
|
ArrayList<Character> row = new ArrayList<>();
|
||||||
|
|
||||||
|
if (line.length() > cols) {
|
||||||
|
cols = line.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Character symbol : line.toCharArray()) {
|
||||||
|
if ((symbol.equals('?')) || (!types.containsKey(symbol))) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
row.add(symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
design.add(row);
|
||||||
|
} else {
|
||||||
|
if ((line.isEmpty()) || (!line.contains("="))) {
|
||||||
|
designing = true;
|
||||||
|
} else {
|
||||||
|
String[] split = line.split("=");
|
||||||
|
String key = split[0].trim();
|
||||||
|
String value = split[1].trim();
|
||||||
|
|
||||||
|
if (key.length() == 1) {
|
||||||
|
Character symbol = key.charAt(0);
|
||||||
|
Material id = Material.getMaterial(value);
|
||||||
|
if (id == null) {
|
||||||
|
throw new Exception("Invalid material in line: " + line);
|
||||||
|
}
|
||||||
|
types.put(symbol, id);
|
||||||
|
frameTypes.add(id);
|
||||||
|
} else {
|
||||||
|
config.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (scanner != null) scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Character[][] layout = new Character[design.size()][cols];
|
||||||
|
|
||||||
|
for (int y = 0; y < design.size(); y++) {
|
||||||
|
ArrayList<Character> row = design.get(y);
|
||||||
|
Character[] result = new Character[cols];
|
||||||
|
|
||||||
|
for (int x = 0; x < cols; x++) {
|
||||||
|
if (x < row.size()) {
|
||||||
|
result[x] = row.get(x);
|
||||||
|
} else {
|
||||||
|
result[x] = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
layout[y] = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gate gate = new Gate(file.getName(), layout, types);
|
||||||
|
|
||||||
|
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
||||||
|
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
||||||
|
gate.button = readConfig(config, gate, file, "button", gate.button);
|
||||||
|
gate.useCost = readConfig(config, gate, file, "usecost", -1);
|
||||||
|
gate.destroyCost = readConfig(config, gate, file, "destroycost", -1);
|
||||||
|
gate.createCost = readConfig(config, gate, file, "createcost", -1);
|
||||||
|
gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : EconomyHandler.toOwner);
|
||||||
|
|
||||||
|
if (gate.getControls().length != 2) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Tag.BUTTONS.isTagged(gate.button)) {
|
||||||
|
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gate button must be a type of button.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge frame types, add open mat to list
|
||||||
|
frameBlocks.addAll(frameTypes);
|
||||||
|
|
||||||
|
gate.save(file.getParent() + "/"); // Updates format for version changes
|
||||||
|
return gate;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) {
|
||||||
|
if (config.containsKey(key)) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(config.get(key));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Material readConfig(HashMap<String, String> config, Gate gate, File file, String key, Material def) {
|
||||||
|
if (config.containsKey(key)) {
|
||||||
|
Material mat = Material.getMaterial(config.get(key));
|
||||||
|
if (mat != null) {
|
||||||
|
return mat;
|
||||||
|
}
|
||||||
|
Stargate.log.log(Level.WARNING, String.format("Error reading %s: %s is not a material", file, key));
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void loadGates(String gateFolder) {
|
||||||
|
File dir = new File(gateFolder);
|
||||||
|
File[] files;
|
||||||
|
|
||||||
|
if (dir.exists()) {
|
||||||
|
files = dir.listFiles(new StargateFilenameFilter());
|
||||||
|
} else {
|
||||||
|
files = new File[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files == null || files.length == 0) {
|
||||||
|
if (dir.mkdir()) {
|
||||||
|
populateDefaults(gateFolder);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (File file : files) {
|
||||||
|
Gate gate = loadGate(file);
|
||||||
|
if (gate != null) registerGate(gate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void populateDefaults(String gateFolder) {
|
||||||
|
Character[][] layout = new Character[][]{
|
||||||
|
{' ', 'X', 'X', ' '},
|
||||||
|
{'X', '.', '.', 'X'},
|
||||||
|
{'-', '.', '.', '-'},
|
||||||
|
{'X', '*', '.', 'X'},
|
||||||
|
{' ', 'X', 'X', ' '},
|
||||||
|
};
|
||||||
|
HashMap<Character, Material> types = new HashMap<>();
|
||||||
|
types.put(ENTRANCE, Material.AIR);
|
||||||
|
types.put(EXIT, Material.AIR);
|
||||||
|
types.put(ANYTHING, Material.AIR);
|
||||||
|
types.put('X', Material.OBSIDIAN);
|
||||||
|
types.put('-', Material.OBSIDIAN);
|
||||||
|
|
||||||
|
Gate gate = new Gate("nethergate.gate", layout, types);
|
||||||
|
gate.save(gateFolder);
|
||||||
|
registerGate(gate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Gate[] getGatesByControlBlock(Block block) {
|
||||||
|
return getGatesByControlBlock(block.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Gate[] getGatesByControlBlock(Material type) {
|
||||||
|
Gate[] result = new Gate[0];
|
||||||
|
ArrayList<Gate> lookup = controlBlocks.get(type);
|
||||||
|
|
||||||
|
if (lookup != null) result = lookup.toArray(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Gate getGateByName(String name) {
|
||||||
|
return gates.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getGateCount() {
|
||||||
|
return gates.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isGateBlock(Material type) {
|
||||||
|
return frameBlocks.contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
static class StargateFilenameFilter implements FilenameFilter {
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
return name.endsWith(".gate");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearGates() {
|
||||||
|
gates.clear();
|
||||||
|
controlBlocks.clear();
|
||||||
|
frameBlocks.clear();
|
||||||
|
}
|
||||||
|
}
|
311
src/main/java/net/knarcraft/stargate/LanguageLoader.java
Normal file
311
src/main/java/net/knarcraft/stargate/LanguageLoader.java
Normal file
@ -0,0 +1,311 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is responsible for loading all strings which are translated into several languages
|
||||||
|
*/
|
||||||
|
public class LanguageLoader {
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
private final String languageFolder;
|
||||||
|
private String chosenLanguage;
|
||||||
|
private Map<String, String> loadedStringTranslations;
|
||||||
|
private final Map<String, String> loadedBackupStrings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new language loader
|
||||||
|
* @param languageFolder <p>The folder containing the language files</p>
|
||||||
|
* @param chosenLanguage <p>The chosen plugin language</p>
|
||||||
|
*/
|
||||||
|
public LanguageLoader(String languageFolder, String chosenLanguage) {
|
||||||
|
this.chosenLanguage = chosenLanguage;
|
||||||
|
this.languageFolder = languageFolder;
|
||||||
|
|
||||||
|
File tmp = new File(languageFolder, chosenLanguage + ".txt");
|
||||||
|
if (!tmp.exists()) {
|
||||||
|
tmp.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
updateLanguage(chosenLanguage);
|
||||||
|
|
||||||
|
loadedStringTranslations = load(chosenLanguage);
|
||||||
|
// We have a default hashMap used for when new text is added.
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream("/lang/" + chosenLanguage + ".txt");
|
||||||
|
if (inputStream != null) {
|
||||||
|
loadedBackupStrings = load("en", inputStream);
|
||||||
|
} else {
|
||||||
|
loadedBackupStrings = null;
|
||||||
|
Stargate.log.severe("[stargate] Error loading backup language. There may be missing text in-game");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads languages from the files on disk
|
||||||
|
*/
|
||||||
|
public void reload() {
|
||||||
|
// This extracts/updates the language as needed
|
||||||
|
updateLanguage(chosenLanguage);
|
||||||
|
loadedStringTranslations = load(chosenLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the string to display given its name/key
|
||||||
|
* @param name <p>The name/key of the string to display</p>
|
||||||
|
* @return <p>The string in the user's preferred language</p>
|
||||||
|
*/
|
||||||
|
public String getString(String name) {
|
||||||
|
String val = loadedStringTranslations.get(name);
|
||||||
|
if (val == null && loadedBackupStrings != null) val = loadedBackupStrings.get(name);
|
||||||
|
if (val == null) return "";
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the chosen plugin language
|
||||||
|
* @param chosenLanguage <p>The new plugin language</p>
|
||||||
|
*/
|
||||||
|
public void setChosenLanguage(String chosenLanguage) {
|
||||||
|
this.chosenLanguage = chosenLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates files in the plugin directory with contents from the compiled .jar
|
||||||
|
* @param language <p>The language to update</p>
|
||||||
|
*/
|
||||||
|
private void updateLanguage(String language) {
|
||||||
|
// Load the current language file
|
||||||
|
ArrayList<String> keyList = new ArrayList<>();
|
||||||
|
ArrayList<String> valueList = new ArrayList<>();
|
||||||
|
|
||||||
|
Map<String, String> currentLanguageValues = load(language);
|
||||||
|
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt");
|
||||||
|
if (inputStream == null) return;
|
||||||
|
|
||||||
|
boolean updated = false;
|
||||||
|
FileOutputStream fileOutputStream = null;
|
||||||
|
try {
|
||||||
|
if (readChangedLanguageStrings(inputStream, keyList, valueList, currentLanguageValues)) {
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
fileOutputStream = new FileOutputStream(languageFolder + language + ".txt");
|
||||||
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
|
||||||
|
BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter);
|
||||||
|
|
||||||
|
// Output normal Language data
|
||||||
|
for (int i = 0; i < keyList.size(); i++) {
|
||||||
|
bufferedWriter.write(keyList.get(i) + valueList.get(i));
|
||||||
|
bufferedWriter.newLine();
|
||||||
|
}
|
||||||
|
bufferedWriter.newLine();
|
||||||
|
// Output any custom language strings the user had
|
||||||
|
if (currentLanguageValues != null) {
|
||||||
|
for (String key : currentLanguageValues.keySet()) {
|
||||||
|
bufferedWriter.write(key + "=" + currentLanguageValues.get(key));
|
||||||
|
bufferedWriter.newLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bufferedWriter.close();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (fileOutputStream != null) {
|
||||||
|
try {
|
||||||
|
fileOutputStream.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
//Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (updated) {
|
||||||
|
Stargate.log.info("[stargate] Your language file (" + language + ".txt) has been updated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads language strings
|
||||||
|
* @param inputStream <p>The input stream to read from</p>
|
||||||
|
* @param keyList <p>The key list to add keys to</p>
|
||||||
|
* @param valueList <p>The value list to add values to</p>
|
||||||
|
* @param currentLanguageValues <p>The current values of the loaded/processed language</p>
|
||||||
|
* @return <p>True if at least one line was updated</p>
|
||||||
|
* @throws IOException <p>if unable to read a language file</p>
|
||||||
|
*/
|
||||||
|
private boolean readChangedLanguageStrings(InputStream inputStream, List<String> keyList, List<String> valueList,
|
||||||
|
Map<String, String> currentLanguageValues) throws IOException {
|
||||||
|
boolean updated = false;
|
||||||
|
// Input stuff
|
||||||
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
|
|
||||||
|
String line = bufferedReader.readLine();
|
||||||
|
boolean firstLine = true;
|
||||||
|
while (line != null) {
|
||||||
|
// Strip UTF BOM
|
||||||
|
if (firstLine) {
|
||||||
|
line = removeUTF8BOM(line);
|
||||||
|
firstLine = false;
|
||||||
|
}
|
||||||
|
// Split at first "="
|
||||||
|
int equalSignIndex = line.indexOf('=');
|
||||||
|
if (equalSignIndex == -1) {
|
||||||
|
keyList.add("");
|
||||||
|
valueList.add("");
|
||||||
|
line = bufferedReader.readLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String key = line.substring(0, equalSignIndex);
|
||||||
|
String value = line.substring(equalSignIndex);
|
||||||
|
|
||||||
|
if (currentLanguageValues == null || currentLanguageValues.get(key) == null) {
|
||||||
|
keyList.add(key);
|
||||||
|
valueList.add(value);
|
||||||
|
updated = true;
|
||||||
|
} else {
|
||||||
|
keyList.add(key);
|
||||||
|
valueList.add("=" + currentLanguageValues.get(key).replace('\u00A7', '&'));
|
||||||
|
currentLanguageValues.remove(key);
|
||||||
|
}
|
||||||
|
line = bufferedReader.readLine();
|
||||||
|
}
|
||||||
|
bufferedReader.close();
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given language
|
||||||
|
* @param lang <p>The language to load</p>
|
||||||
|
* @return <p>A mapping between loaded string indexes and the strings to display</p>
|
||||||
|
*/
|
||||||
|
private Map<String, String> load(String lang) {
|
||||||
|
return load(lang, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the given language
|
||||||
|
* @param lang <p>The language to load</p>
|
||||||
|
* @param inputStream <p>An optional input stream to use. Defaults to using a file input stream</p>
|
||||||
|
* @return <p>A mapping between loaded string indexes and the strings to display</p>
|
||||||
|
*/
|
||||||
|
private Map<String, String> load(String lang, InputStream inputStream) {
|
||||||
|
Map<String, String> strings = new HashMap<>();
|
||||||
|
FileInputStream fileInputStream = null;
|
||||||
|
InputStreamReader inputStreamReader;
|
||||||
|
try {
|
||||||
|
if (inputStream == null) {
|
||||||
|
fileInputStream = new FileInputStream(languageFolder + lang + ".txt");
|
||||||
|
inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
|
||||||
|
} else {
|
||||||
|
inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
readLanguageFile(inputStreamReader, strings);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (fileInputStream != null) {
|
||||||
|
try {
|
||||||
|
fileInputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
//Ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a language file given its input stream
|
||||||
|
* @param inputStreamReader <p>The input stream reader to read from</p>
|
||||||
|
* @param strings <p>The loaded string pairs</p>
|
||||||
|
* @throws IOException <p>If unable to read the file</p>
|
||||||
|
*/
|
||||||
|
private void readLanguageFile(InputStreamReader inputStreamReader, Map<String, String> strings) throws IOException {
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
|
String line = bufferedReader.readLine();
|
||||||
|
boolean firstLine = true;
|
||||||
|
while (line != null) {
|
||||||
|
// Strip UTF BOM
|
||||||
|
if (firstLine) {
|
||||||
|
line = removeUTF8BOM(line);
|
||||||
|
firstLine = false;
|
||||||
|
}
|
||||||
|
// Split at first "="
|
||||||
|
int equalSignIndex = line.indexOf('=');
|
||||||
|
if (equalSignIndex == -1) {
|
||||||
|
line = bufferedReader.readLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String key = line.substring(0, equalSignIndex);
|
||||||
|
String val = ChatColor.translateAlternateColorCodes('&', line.substring(equalSignIndex + 1));
|
||||||
|
strings.put(key, val);
|
||||||
|
line = bufferedReader.readLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints debug output to the console for checking of loading language strings/translations
|
||||||
|
*/
|
||||||
|
public void debug() {
|
||||||
|
Set<String> keys = loadedStringTranslations.keySet();
|
||||||
|
for (String key : keys) {
|
||||||
|
Stargate.debug("LanguageLoader::Debug::loadedStringTranslations", key + " => " + loadedStringTranslations.get(key));
|
||||||
|
}
|
||||||
|
if (loadedBackupStrings == null) return;
|
||||||
|
keys = loadedBackupStrings.keySet();
|
||||||
|
for (String key : keys) {
|
||||||
|
Stargate.debug("LanguageLoader::Debug::loadedBackupStrings", key + " => " + loadedBackupStrings.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the UTF-8 Byte Order Mark if present
|
||||||
|
* @param string <p>The string to remove the BOM from</p>
|
||||||
|
* @return <p>A string guaranteed without a BOM</p>
|
||||||
|
*/
|
||||||
|
private String removeUTF8BOM(String string) {
|
||||||
|
String UTF8_BOM = "\uFEFF";
|
||||||
|
if (string.startsWith(UTF8_BOM)) {
|
||||||
|
string = string.substring(1);
|
||||||
|
}
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1503
src/main/java/net/knarcraft/stargate/Portal.java
Normal file
1503
src/main/java/net/knarcraft/stargate/Portal.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,26 +1,28 @@
|
|||||||
package net.TheDgtl.Stargate;
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stargate - A portal plugin for Bukkit
|
* stargate - A portal plugin for Bukkit
|
||||||
* Copyright (C) 2011 Shaun (sturmeh)
|
* Copyright (C) 2011 Shaun (sturmeh)
|
||||||
* Copyright (C) 2011 Dinnerbone
|
* Copyright (C) 2011 Dinnerbone
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
*
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class RelativeBlockVector {
|
public class RelativeBlockVector {
|
||||||
|
|
||||||
private int right = 0;
|
private int right = 0;
|
||||||
private int depth = 0;
|
private int depth = 0;
|
||||||
private int distance = 0;
|
private int distance = 0;
|
||||||
@ -42,4 +44,5 @@ public class RelativeBlockVector {
|
|||||||
public int getDistance() {
|
public int getDistance() {
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
34
src/main/java/net/knarcraft/stargate/StarGateThread.java
Normal file
34
src/main/java/net/knarcraft/stargate/StarGateThread.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package net.knarcraft.stargate;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class contains the function used to close servers which should no longer be open/active
|
||||||
|
*/
|
||||||
|
public class StarGateThread implements Runnable {
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
long time = System.currentTimeMillis() / 1000;
|
||||||
|
// Close open portals
|
||||||
|
for (Iterator<Portal> iterator = Stargate.openList.iterator(); iterator.hasNext(); ) {
|
||||||
|
Portal p = iterator.next();
|
||||||
|
// Skip always open gates
|
||||||
|
if (p.isAlwaysOn()) continue;
|
||||||
|
if (!p.isOpen()) continue;
|
||||||
|
if (time > p.getOpenTime() + Stargate.getOpenTime()) {
|
||||||
|
p.close(false);
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Deactivate active portals
|
||||||
|
for (Iterator<Portal> iterator = Stargate.activeList.iterator(); iterator.hasNext(); ) {
|
||||||
|
Portal p = iterator.next();
|
||||||
|
if (!p.isActive()) continue;
|
||||||
|
if (time > p.getOpenTime() + Stargate.getActiveTime()) {
|
||||||
|
p.deactivate();
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
1280
src/main/java/net/knarcraft/stargate/Stargate.java
Normal file
1280
src/main/java/net/knarcraft/stargate/Stargate.java
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,13 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
/*
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@ -23,12 +23,16 @@ import net.TheDgtl.Stargate.Portal;
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class StargateAccessEvent extends StargateEvent {
|
public class StargateAccessEvent extends StargateEvent {
|
||||||
|
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private boolean deny;
|
private boolean deny;
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
@ -44,10 +48,18 @@ public class StargateAccessEvent extends StargateEvent {
|
|||||||
this.deny = deny;
|
this.deny = deny;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether the player should be denied access
|
||||||
|
* @return <p>Whether the player should be denied access</p>
|
||||||
|
*/
|
||||||
public boolean getDeny() {
|
public boolean getDeny() {
|
||||||
return this.deny;
|
return this.deny;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether to deny the player
|
||||||
|
* @param deny <p>Whether to deny the player</p>
|
||||||
|
*/
|
||||||
public void setDeny(boolean deny) {
|
public void setDeny(boolean deny) {
|
||||||
this.deny = deny;
|
this.deny = deny;
|
||||||
}
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StargateActivateEvent extends StargateEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private ArrayList<String> destinations;
|
||||||
|
private String destination;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StargateActivateEvent(Portal portal, Player player, ArrayList<String> destinations, String destination) {
|
||||||
|
super("StargatActivateEvent", portal);
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
|
this.destinations = destinations;
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getDestinations() {
|
||||||
|
return destinations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestinations(ArrayList<String> destinations) {
|
||||||
|
this.destinations = destinations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDestination() {
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestination(String destination) {
|
||||||
|
this.destination = destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,28 +1,29 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stargate - A portal plugin for Bukkit
|
* stargate - A portal plugin for Bukkit
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
*
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class StargateCloseEvent extends StargateEvent {
|
public class StargateCloseEvent extends StargateEvent {
|
||||||
|
|
||||||
private boolean force;
|
private boolean force;
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
@ -34,6 +35,7 @@ public class StargateCloseEvent extends StargateEvent {
|
|||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StargateCloseEvent(Portal portal, boolean force) {
|
public StargateCloseEvent(Portal portal, boolean force) {
|
||||||
super("StargateCloseEvent", portal);
|
super("StargateCloseEvent", portal);
|
||||||
|
|
||||||
@ -47,4 +49,5 @@ public class StargateCloseEvent extends StargateEvent {
|
|||||||
public void setForce(boolean force) {
|
public void setForce(boolean force) {
|
||||||
this.force = force;
|
this.force = force;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StargateCreateEvent extends StargateEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private boolean deny;
|
||||||
|
private String denyReason;
|
||||||
|
private final String[] lines;
|
||||||
|
private int cost;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StargateCreateEvent(Player player, Portal portal, String[] lines, boolean deny, String denyReason, int cost) {
|
||||||
|
super("StargateCreateEvent", portal);
|
||||||
|
this.player = player;
|
||||||
|
this.lines = lines;
|
||||||
|
this.deny = deny;
|
||||||
|
this.denyReason = denyReason;
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||||
|
return lines[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeny() {
|
||||||
|
return deny;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeny(boolean deny) {
|
||||||
|
this.deny = deny;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDenyReason() {
|
||||||
|
return denyReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDenyReason(String denyReason) {
|
||||||
|
this.denyReason = denyReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCost() {
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCost(int cost) {
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,28 +1,29 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stargate - A portal plugin for Bukkit
|
* stargate - A portal plugin for Bukkit
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
*
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class StargateDeactivateEvent extends StargateEvent {
|
public class StargateDeactivateEvent extends StargateEvent {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
@ -32,6 +33,7 @@ public class StargateDeactivateEvent extends StargateEvent {
|
|||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StargateDeactivateEvent(Portal portal) {
|
public StargateDeactivateEvent(Portal portal) {
|
||||||
super("StargatDeactivateEvent", portal);
|
super("StargatDeactivateEvent", portal);
|
||||||
|
|
@ -0,0 +1,79 @@
|
|||||||
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StargateDestroyEvent extends StargateEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private boolean deny;
|
||||||
|
private String denyReason;
|
||||||
|
private int cost;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StargateDestroyEvent(Portal portal, Player player, boolean deny, String denyMsg, int cost) {
|
||||||
|
super("StargateDestroyEvent", portal);
|
||||||
|
this.player = player;
|
||||||
|
this.deny = deny;
|
||||||
|
this.denyReason = denyMsg;
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeny() {
|
||||||
|
return deny;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeny(boolean deny) {
|
||||||
|
this.deny = deny;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDenyReason() {
|
||||||
|
return denyReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDenyReason(String denyReason) {
|
||||||
|
this.denyReason = denyReason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCost() {
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCost(int cost) {
|
||||||
|
this.cost = cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,29 +1,34 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Stargate - A portal plugin for Bukkit
|
* stargate - A portal plugin for Bukkit
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
*
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
* <p>
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
* <p>
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract event describing any stargate event
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public abstract class StargateEvent extends Event implements Cancellable {
|
public abstract class StargateEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
protected Portal portal;
|
protected Portal portal;
|
||||||
protected boolean cancelled;
|
protected boolean cancelled;
|
||||||
|
|
||||||
@ -45,4 +50,5 @@ public abstract class StargateEvent extends Event implements Cancellable {
|
|||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StargateOpenEvent extends StargateEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private boolean force;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StargateOpenEvent(Player player, Portal portal, boolean force) {
|
||||||
|
super("StargateOpenEvent", portal);
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
|
this.force = force;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the player than opened the gate.
|
||||||
|
*
|
||||||
|
* @return player than opened the gate
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getForce() {
|
||||||
|
return force;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForce(boolean force) {
|
||||||
|
this.force = force;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package net.knarcraft.stargate.event;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Portal;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stargate - A portal plugin for Bukkit
|
||||||
|
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
||||||
|
* Copyright (C) 2021 Kristian Knarvik
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
* <p>
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
* <p>
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class StargatePortalEvent extends StargateEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final Portal destination;
|
||||||
|
private Location exit;
|
||||||
|
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StargatePortalEvent(Player player, Portal portal, Portal dest, Location exit) {
|
||||||
|
super("StargatePortalEvent", portal);
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
|
this.destination = dest;
|
||||||
|
this.exit = exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the player that went through the gate.
|
||||||
|
*
|
||||||
|
* @return player that went through the gate
|
||||||
|
*/
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the destination gate
|
||||||
|
*
|
||||||
|
* @return destination gate
|
||||||
|
*/
|
||||||
|
public Portal getDestination() {
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the location of the players exit point
|
||||||
|
*
|
||||||
|
* @return org.bukkit.Location Location of the exit point
|
||||||
|
*/
|
||||||
|
public Location getExit() {
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the location of the players exit point
|
||||||
|
*/
|
||||||
|
public void setExit(Location loc) {
|
||||||
|
this.exit = loc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
# Stargate Configuration File
|
# stargate Configuration File
|
||||||
# Main Stargate config
|
# Main stargate config
|
||||||
#
|
#
|
||||||
# portal-folder - The folder for storing portals
|
# portal-folder - The folder for storing portals
|
||||||
# gate-folder - The folder for storing gate layouts
|
# gate-folder - The folder for storing gate layouts
|
||||||
@ -15,7 +15,7 @@
|
|||||||
# signColor - The color used for drawing signs (Default: BLACK).
|
# signColor - The color used for drawing signs (Default: BLACK).
|
||||||
# verifyPortals - Whether or not all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
# verifyPortals - Whether or not all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
||||||
############################
|
############################
|
||||||
# Stargate economy options #
|
# stargate economy options #
|
||||||
############################
|
############################
|
||||||
# useeconomy - Whether to use an economy plugin
|
# useeconomy - Whether to use an economy plugin
|
||||||
# createcost - The cost to create a gate
|
# createcost - The cost to create a gate
|
||||||
@ -29,8 +29,8 @@
|
|||||||
#################
|
#################
|
||||||
# debug - Debug -- Only enable if you have issues, massive console output
|
# debug - Debug -- Only enable if you have issues, massive console output
|
||||||
# permdebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
|
# permdebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
|
||||||
portal-folder: plugins/Stargate/portals/
|
portal-folder: plugins/stargate/portals/
|
||||||
gate-folder: plugins/Stargate/gates/
|
gate-folder: plugins/stargate/gates/
|
||||||
default-gate-network: central
|
default-gate-network: central
|
||||||
destroyexplosion: false
|
destroyexplosion: false
|
||||||
maxgates: 0
|
maxgates: 0
|
@ -16,7 +16,7 @@ createMsg=Gate erstellt.
|
|||||||
createNetDeny=Du hast keinen Zugriff auf dieses Netzwerk.
|
createNetDeny=Du hast keinen Zugriff auf dieses Netzwerk.
|
||||||
createGateDeny=Du hast keinen Zugriff auf dieses Gate-Layout.
|
createGateDeny=Du hast keinen Zugriff auf dieses Gate-Layout.
|
||||||
createPersonal=Gate im persönlichen Netzwerk erstellt.
|
createPersonal=Gate im persönlichen Netzwerk erstellt.
|
||||||
createNameLength=Name zu kurz oder zu lang.
|
createNameLength=Name zu kurz oder zu chosenLanguage.
|
||||||
createExists=Ein Gate mit diesem Name existiert bereits.
|
createExists=Ein Gate mit diesem Name existiert bereits.
|
||||||
createFull=Dieses Netzwerk ist voll.
|
createFull=Dieses Netzwerk ist voll.
|
||||||
createWorldDeny=Du hast keinen Zugriff auf diese Welt.
|
createWorldDeny=Du hast keinen Zugriff auf diese Welt.
|
@ -16,7 +16,7 @@ createMsg=Gate gemaakt
|
|||||||
createNetDeny=Je hebt geen toegang tot dat netwerk.
|
createNetDeny=Je hebt geen toegang tot dat netwerk.
|
||||||
createGateDeny=Je mag die Gate-Layout niet gebruiken
|
createGateDeny=Je mag die Gate-Layout niet gebruiken
|
||||||
createPersonal=Gate op persoonlijk netwerk gemaakt.
|
createPersonal=Gate op persoonlijk netwerk gemaakt.
|
||||||
createNameLength=Naam te lang of te kort.
|
createNameLength=Naam te chosenLanguage of te kort.
|
||||||
createExists=Er bestaat al een gate met die naam
|
createExists=Er bestaat al een gate met die naam
|
||||||
createFull=Dit netwerk is vol.
|
createFull=Dit netwerk is vol.
|
||||||
createWorldDeny=Je mag niet in die wereld komen.
|
createWorldDeny=Je mag niet in die wereld komen.
|
@ -1,10 +1,10 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.TheDgtl.Stargate.Stargate
|
main: net.knarcraft.stargate.Stargate
|
||||||
version: 0.8.0.3
|
version: 0.8.0.0
|
||||||
description: Stargate mod for Bukkit
|
description: Stargate mod for Bukkit
|
||||||
author: Drakia
|
author: EpicKnarvik97
|
||||||
website: http://www.thedgtl.net
|
website: https://knarcraft.net
|
||||||
api-version: 1.13
|
api-version: 1.16
|
||||||
commands:
|
commands:
|
||||||
sg:
|
sg:
|
||||||
description: Used to reload the plugin. Console use only.
|
description: Used to reload the plugin. Console use only.
|
@ -1,173 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
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.block.data.BlockData;
|
|
||||||
import org.bukkit.block.data.type.Sign;
|
|
||||||
import org.bukkit.block.data.type.WallSign;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011 Shaun (sturmeh)
|
|
||||||
* Copyright (C) 2011 Dinnerbone
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Blox {
|
|
||||||
private final int x;
|
|
||||||
private final int y;
|
|
||||||
private final int z;
|
|
||||||
private final World world;
|
|
||||||
private Blox parent = null;
|
|
||||||
|
|
||||||
public Blox (World world, int x, int y, int z) {
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.z = z;
|
|
||||||
this.world = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox (Block block) {
|
|
||||||
this.x = block.getX();
|
|
||||||
this.y = block.getY();
|
|
||||||
this.z = block.getZ();
|
|
||||||
this.world = block.getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox (Location location) {
|
|
||||||
this.x = location.getBlockX();
|
|
||||||
this.y = location.getBlockY();
|
|
||||||
this.z = location.getBlockZ();
|
|
||||||
this.world = location.getWorld();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox (World world, String string) {
|
|
||||||
String[] split = string.split(",");
|
|
||||||
this.x = Integer.parseInt(split[0]);
|
|
||||||
this.y = Integer.parseInt(split[1]);
|
|
||||||
this.z = Integer.parseInt(split[2]);
|
|
||||||
this.world = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox makeRelative(int x, int y, int z) {
|
|
||||||
return new Blox(this.world, this.x + x, this.y + y, this.z + z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location makeRelativeLoc(double x, double y, double z, float rotX, float rotY) {
|
|
||||||
return new Location(this.world, (double)this.x + x, (double)this.y + y, (double)this.z + z, rotX, rotY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox modRelative(int right, int depth, int distance, int modX, int modY, int modZ) {
|
|
||||||
return makeRelative(-right * modX + distance * modZ, -depth * modY, -right * modZ + -distance * modX);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location modRelativeLoc(double right, double depth, double distance, float rotX, float rotY, int modX, int modY, int modZ) {
|
|
||||||
return makeRelativeLoc(0.5 + -right * modX + distance * modZ, depth, 0.5 + -right * modZ + -distance * modX, rotX, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(Material type) {
|
|
||||||
world.getBlockAt(x, y, z).setType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getType() {
|
|
||||||
return world.getBlockAt(x, y, z).getType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block getBlock() {
|
|
||||||
return world.getBlockAt(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return new Location(world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getZ() {
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public World getWorld() {
|
|
||||||
return world;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Block getParent() {
|
|
||||||
if (parent == null) findParent();
|
|
||||||
if (parent == null) return null;
|
|
||||||
return parent.getBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void findParent() {
|
|
||||||
int offsetX = 0;
|
|
||||||
int offsetY = 0;
|
|
||||||
int offsetZ = 0;
|
|
||||||
|
|
||||||
BlockData blk = getBlock().getBlockData();
|
|
||||||
if (blk instanceof WallSign) {
|
|
||||||
BlockFace facing = ((WallSign) blk).getFacing().getOppositeFace();
|
|
||||||
offsetX = facing.getModX();
|
|
||||||
offsetZ = facing.getModZ();
|
|
||||||
} else if (blk instanceof Sign) {
|
|
||||||
offsetY = -1;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parent = new Blox(world, getX() + offsetX, getY() + offsetY, getZ() + offsetZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
//builder.append(world.getName());
|
|
||||||
//builder.append(',');
|
|
||||||
builder.append(x);
|
|
||||||
builder.append(',');
|
|
||||||
builder.append(y);
|
|
||||||
builder.append(',');
|
|
||||||
builder.append(z);
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
int result = 18;
|
|
||||||
|
|
||||||
result = result * 27 + x;
|
|
||||||
result = result * 27 + y;
|
|
||||||
result = result * 27 + z;
|
|
||||||
result = result * 27 + world.getName().hashCode();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) return true;
|
|
||||||
if (obj == null) return false;
|
|
||||||
if (getClass() != obj.getClass()) return false;
|
|
||||||
|
|
||||||
Blox blox = (Blox) obj;
|
|
||||||
return (x == blox.x) && (y == blox.y) && (z == blox.z) && (world.getName().equals(blox.world.getName()));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import org.bukkit.Axis;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
|
|
||||||
public class BloxPopulator {
|
|
||||||
private Blox blox;
|
|
||||||
private Material nextMat;
|
|
||||||
private Axis nextAxis;
|
|
||||||
|
|
||||||
public BloxPopulator(Blox b, Material m) {
|
|
||||||
blox = b;
|
|
||||||
nextMat = m;
|
|
||||||
nextAxis = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BloxPopulator(Blox b, Material m, Axis a) {
|
|
||||||
blox = b;
|
|
||||||
nextMat = m;
|
|
||||||
nextAxis = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlox(Blox b) {
|
|
||||||
blox = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMat(Material m) {
|
|
||||||
nextMat = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAxis(Axis a) {
|
|
||||||
nextAxis = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Blox getBlox() {
|
|
||||||
return blox;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getMat() {
|
|
||||||
return nextMat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Axis getAxis() {
|
|
||||||
return nextAxis;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.PluginManager;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class EconomyHandler {
|
|
||||||
public static boolean economyEnabled = false;
|
|
||||||
public static Economy economy = null;
|
|
||||||
public static Plugin vault = null;
|
|
||||||
|
|
||||||
public static int useCost = 0;
|
|
||||||
public static int createCost = 0;
|
|
||||||
public static int destroyCost = 0;
|
|
||||||
public static boolean toOwner = false;
|
|
||||||
public static boolean chargeFreeDestination = true;
|
|
||||||
public static boolean freeGatesGreen = false;
|
|
||||||
|
|
||||||
public static double getBalance(Player player) {
|
|
||||||
if (!economyEnabled) return 0;
|
|
||||||
return economy.getBalance(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean chargePlayer(Player player, String target, double amount) {
|
|
||||||
if (!economyEnabled) return true;
|
|
||||||
if(player.getName().equals(target)) return true;
|
|
||||||
if(economy != null) {
|
|
||||||
if(!economy.has(player, amount)) return false;
|
|
||||||
economy.withdrawPlayer(player, amount);
|
|
||||||
economy.depositPlayer(target, amount);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean chargePlayer(Player player, UUID target, double amount) {
|
|
||||||
if (!economyEnabled) return true;
|
|
||||||
if(player.getUniqueId().compareTo(target) == 0) return true;
|
|
||||||
if(economy != null) {
|
|
||||||
if(!economy.has(player, amount)) return false;
|
|
||||||
economy.withdrawPlayer(player, amount);
|
|
||||||
economy.depositPlayer(Bukkit.getOfflinePlayer(target), amount);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean chargePlayer(Player player, double amount) {
|
|
||||||
if (!economyEnabled) return true;
|
|
||||||
if(economy != null) {
|
|
||||||
if(!economy.has(player, amount)) return false;
|
|
||||||
economy.withdrawPlayer(player, amount);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String format(int amt) {
|
|
||||||
if (economyEnabled) {
|
|
||||||
return economy.format(amt);
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean setupEconomy(PluginManager pm) {
|
|
||||||
if (!economyEnabled) return false;
|
|
||||||
// Check for Vault
|
|
||||||
Plugin p = pm.getPlugin("Vault");
|
|
||||||
if (p != null && p.isEnabled()) {
|
|
||||||
RegisteredServiceProvider<Economy> economyProvider = Stargate.server.getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
|
|
||||||
if (economyProvider != null) {
|
|
||||||
economy = economyProvider.getProvider();
|
|
||||||
vault = p;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
economyEnabled = false;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean useEconomy() {
|
|
||||||
return economyEnabled && economy != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,513 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Tag;
|
|
||||||
import org.bukkit.block.Block;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011 Shaun (sturmeh)
|
|
||||||
* Copyright (C) 2011 Dinnerbone
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class Gate {
|
|
||||||
private static final Character ANYTHING = ' ';
|
|
||||||
private static final Character ENTRANCE = '.';
|
|
||||||
private static final Character EXIT = '*';
|
|
||||||
private static final HashMap<String, Gate> gates = new HashMap<>();
|
|
||||||
private static final HashMap<Material, ArrayList<Gate>> controlBlocks = new HashMap<>();
|
|
||||||
private static final HashSet<Material> frameBlocks = new HashSet<>();
|
|
||||||
|
|
||||||
private final String filename;
|
|
||||||
private final Character[][] layout;
|
|
||||||
private final HashMap<Character, Material> types;
|
|
||||||
private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
|
|
||||||
private RelativeBlockVector[] border = new RelativeBlockVector[0];
|
|
||||||
private RelativeBlockVector[] controls = new RelativeBlockVector[0];
|
|
||||||
private RelativeBlockVector exitBlock = null;
|
|
||||||
private final HashMap<RelativeBlockVector, Integer> exits = new HashMap<>();
|
|
||||||
private Material portalBlockOpen = Material.NETHER_PORTAL;
|
|
||||||
private Material portalBlockClosed = Material.AIR;
|
|
||||||
private Material button = Material.STONE_BUTTON;
|
|
||||||
|
|
||||||
// Economy information
|
|
||||||
private int useCost = -1;
|
|
||||||
private int createCost = -1;
|
|
||||||
private int destroyCost = -1;
|
|
||||||
private boolean toOwner = false;
|
|
||||||
|
|
||||||
public Gate(String filename, Character[][] layout, HashMap<Character, Material> types) {
|
|
||||||
this.filename = filename;
|
|
||||||
this.layout = layout;
|
|
||||||
this.types = types;
|
|
||||||
|
|
||||||
populateCoordinates();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void populateCoordinates() {
|
|
||||||
ArrayList<RelativeBlockVector> entranceList = new ArrayList<>();
|
|
||||||
ArrayList<RelativeBlockVector> borderList = new ArrayList<>();
|
|
||||||
ArrayList<RelativeBlockVector> controlList = new ArrayList<>();
|
|
||||||
RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
|
|
||||||
int[] exitDepths = new int[layout[0].length];
|
|
||||||
RelativeBlockVector lastExit = null;
|
|
||||||
|
|
||||||
for (int y = 0; y < layout.length; y++) {
|
|
||||||
for (int x = 0; x < layout[y].length; x++) {
|
|
||||||
Character key = layout[y][x];
|
|
||||||
if (key.equals('-')) {
|
|
||||||
controlList.add(new RelativeBlockVector(x, y, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key.equals(ENTRANCE) || key.equals(EXIT)) {
|
|
||||||
entranceList.add(new RelativeBlockVector(x, y, 0));
|
|
||||||
exitDepths[x] = y;
|
|
||||||
if (key.equals(EXIT)) {
|
|
||||||
this.exitBlock = new RelativeBlockVector(x, y, 0);
|
|
||||||
}
|
|
||||||
} else if (!key.equals(ANYTHING)) {
|
|
||||||
borderList.add(new RelativeBlockVector(x, y, 0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int x = 0; x < exitDepths.length; x++) {
|
|
||||||
relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int x = relativeExits.length - 1; x >= 0; x--) {
|
|
||||||
if (relativeExits[x] != null) {
|
|
||||||
lastExit = relativeExits[x];
|
|
||||||
} else {
|
|
||||||
relativeExits[x] = lastExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.entrances = entranceList.toArray(this.entrances);
|
|
||||||
this.border = borderList.toArray(this.border);
|
|
||||||
this.controls = controlList.toArray(this.controls);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(String gateFolder) {
|
|
||||||
try {
|
|
||||||
BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
|
|
||||||
|
|
||||||
writeConfig(bw, "portal-open", portalBlockOpen.name());
|
|
||||||
writeConfig(bw, "portal-closed", portalBlockClosed.name());
|
|
||||||
writeConfig(bw, "button", button.name());
|
|
||||||
if (useCost != -1)
|
|
||||||
writeConfig(bw, "usecost", useCost);
|
|
||||||
if (createCost != -1)
|
|
||||||
writeConfig(bw, "createcost", createCost);
|
|
||||||
if (destroyCost != -1)
|
|
||||||
writeConfig(bw, "destroycost", destroyCost);
|
|
||||||
writeConfig(bw, "toowner", toOwner);
|
|
||||||
|
|
||||||
for (Map.Entry<Character, Material> entry : types.entrySet()) {
|
|
||||||
Character type = entry.getKey();
|
|
||||||
Material value = entry.getValue();
|
|
||||||
// Skip control values
|
|
||||||
if (type.equals(ANYTHING) || type.equals(ENTRANCE) || type.equals(EXIT)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bw.append(type);
|
|
||||||
bw.append('=');
|
|
||||||
if(value != null) {
|
|
||||||
bw.append(value.toString());
|
|
||||||
}
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
bw.newLine();
|
|
||||||
|
|
||||||
for(Character[] aLayout : layout) {
|
|
||||||
for(Character symbol : aLayout) {
|
|
||||||
bw.append(symbol);
|
|
||||||
}
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
bw.close();
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Stargate.log.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
|
|
||||||
bw.append(String.format("%s=%d", key, value));
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException {
|
|
||||||
bw.append(String.format("%s=%b", key, value));
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeConfig(BufferedWriter bw, String key, String value) throws IOException {
|
|
||||||
bw.append(String.format("%s=%s", key, value));
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Character[][] getLayout() {
|
|
||||||
return layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<Character, Material> getTypes() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RelativeBlockVector[] getEntrances() {
|
|
||||||
return entrances;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RelativeBlockVector[] getBorder() {
|
|
||||||
return border;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RelativeBlockVector[] getControls() {
|
|
||||||
return controls;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<RelativeBlockVector, Integer> getExits() {
|
|
||||||
return exits;
|
|
||||||
}
|
|
||||||
public RelativeBlockVector getExit() {
|
|
||||||
return exitBlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getControlBlock() {
|
|
||||||
return types.get('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFilename() {
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getPortalBlockOpen() {
|
|
||||||
return portalBlockOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPortalBlockOpen(Material type) {
|
|
||||||
portalBlockOpen = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getPortalBlockClosed() {
|
|
||||||
return portalBlockClosed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPortalBlockClosed(Material type) {
|
|
||||||
portalBlockClosed = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Material getButton() {
|
|
||||||
return button;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getUseCost() {
|
|
||||||
if (useCost < 0) return EconomyHandler.useCost;
|
|
||||||
return useCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getCreateCost() {
|
|
||||||
if (createCost < 0) return EconomyHandler.createCost;
|
|
||||||
return createCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getDestroyCost() {
|
|
||||||
if (destroyCost < 0) return EconomyHandler.destroyCost;
|
|
||||||
return destroyCost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getToOwner() {
|
|
||||||
return toOwner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Blox topleft, int modX, int modZ) {
|
|
||||||
return matches(topleft, modX, modZ, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean matches(Blox topleft, int modX, int modZ, boolean onCreate) {
|
|
||||||
HashMap<Character, Material> portalTypes = new HashMap<>(types);
|
|
||||||
for (int y = 0; y < layout.length; y++) {
|
|
||||||
for (int x = 0; x < layout[y].length; x++) {
|
|
||||||
Character key = layout[y][x];
|
|
||||||
|
|
||||||
if (key.equals(ENTRANCE) || key.equals(EXIT)) {
|
|
||||||
if (Stargate.ignoreEntrance) continue;
|
|
||||||
|
|
||||||
Material type = topleft.modRelative(x, y, 0, modX, 1, modZ).getType();
|
|
||||||
|
|
||||||
// Ignore entrance if it's air and we're creating a new gate
|
|
||||||
if (onCreate && type == Material.AIR) continue;
|
|
||||||
|
|
||||||
if (type != portalBlockClosed && type != portalBlockOpen) {
|
|
||||||
Stargate.debug("Gate::Matches", "Entrance/Exit Material Mismatch: " + type);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!key.equals(ANYTHING)) {
|
|
||||||
Material id = portalTypes.get(key);
|
|
||||||
if(id == null) {
|
|
||||||
portalTypes.put(key, topleft.modRelative(x, y, 0, modX, 1, modZ).getType());
|
|
||||||
} else if(topleft.modRelative(x, y, 0, modX, 1, modZ).getType() != id) {
|
|
||||||
Stargate.debug("Gate::Matches", "Block Type Mismatch: " + topleft.modRelative(x, y, 0, modX, 1, modZ).getType() + " != " + id);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void registerGate(Gate gate) {
|
|
||||||
gates.put(gate.getFilename(), gate);
|
|
||||||
|
|
||||||
Material blockID = gate.getControlBlock();
|
|
||||||
|
|
||||||
if (!controlBlocks.containsKey(blockID)) {
|
|
||||||
controlBlocks.put(blockID, new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
controlBlocks.get(blockID).add(gate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gate loadGate(File file) {
|
|
||||||
Scanner scanner = null;
|
|
||||||
boolean designing = false;
|
|
||||||
ArrayList<ArrayList<Character>> design = new ArrayList<>();
|
|
||||||
HashMap<Character, Material> types = new HashMap<>();
|
|
||||||
HashMap<String, String> config = new HashMap<>();
|
|
||||||
HashSet<Material> frameTypes = new HashSet<>();
|
|
||||||
int cols = 0;
|
|
||||||
|
|
||||||
// Init types map
|
|
||||||
types.put(ENTRANCE, Material.AIR);
|
|
||||||
types.put(EXIT, Material.AIR);
|
|
||||||
types.put(ANYTHING, Material.AIR);
|
|
||||||
|
|
||||||
try {
|
|
||||||
scanner = new Scanner(file);
|
|
||||||
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
|
|
||||||
if (designing) {
|
|
||||||
ArrayList<Character> row = new ArrayList<>();
|
|
||||||
|
|
||||||
if (line.length() > cols) {
|
|
||||||
cols = line.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Character symbol : line.toCharArray()) {
|
|
||||||
if ((symbol.equals('?')) || (!types.containsKey(symbol))) {
|
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Unknown symbol '" + symbol + "' in diagram");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
row.add(symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
design.add(row);
|
|
||||||
} else {
|
|
||||||
if ((line.isEmpty()) || (!line.contains("="))) {
|
|
||||||
designing = true;
|
|
||||||
} else {
|
|
||||||
String[] split = line.split("=");
|
|
||||||
String key = split[0].trim();
|
|
||||||
String value = split[1].trim();
|
|
||||||
|
|
||||||
if (key.length() == 1) {
|
|
||||||
Character symbol = key.charAt(0);
|
|
||||||
Material id = Material.getMaterial(value);
|
|
||||||
if(id == null) {
|
|
||||||
throw new Exception("Invalid material in line: " + line);
|
|
||||||
}
|
|
||||||
types.put(symbol, id);
|
|
||||||
frameTypes.add(id);
|
|
||||||
} else {
|
|
||||||
config.put(key, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - " + ex.getMessage());
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
if (scanner != null) scanner.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
Character[][] layout = new Character[design.size()][cols];
|
|
||||||
|
|
||||||
for (int y = 0; y < design.size(); y++) {
|
|
||||||
ArrayList<Character> row = design.get(y);
|
|
||||||
Character[] result = new Character[cols];
|
|
||||||
|
|
||||||
for (int x = 0; x < cols; x++) {
|
|
||||||
if (x < row.size()) {
|
|
||||||
result[x] = row.get(x);
|
|
||||||
} else {
|
|
||||||
result[x] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
layout[y] = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gate gate = new Gate(file.getName(), layout, types);
|
|
||||||
|
|
||||||
gate.portalBlockOpen = readConfig(config, gate, file, "portal-open", gate.portalBlockOpen);
|
|
||||||
gate.portalBlockClosed = readConfig(config, gate, file, "portal-closed", gate.portalBlockClosed);
|
|
||||||
gate.button = readConfig(config, gate, file, "button", gate.button);
|
|
||||||
gate.useCost = readConfig(config, gate, file, "usecost", -1);
|
|
||||||
gate.destroyCost = readConfig(config, gate, file, "destroycost", -1);
|
|
||||||
gate.createCost = readConfig(config, gate, file, "createcost", -1);
|
|
||||||
gate.toOwner = (config.containsKey("toowner") ? Boolean.valueOf(config.get("toowner")) : EconomyHandler.toOwner);
|
|
||||||
|
|
||||||
if (gate.getControls().length != 2) {
|
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gates must have exactly 2 control points.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Tag.BUTTONS.isTagged(gate.button)) {
|
|
||||||
Stargate.log.log(Level.SEVERE, "Could not load Gate " + file.getName() + " - Gate button must be a type of button.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge frame types, add open mat to list
|
|
||||||
frameBlocks.addAll(frameTypes);
|
|
||||||
|
|
||||||
gate.save(file.getParent() + "/"); // Updates format for version changes
|
|
||||||
return gate;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int readConfig(HashMap<String, String> config, Gate gate, File file, String key, int def) {
|
|
||||||
if (config.containsKey(key)) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(config.get(key));
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
Stargate.log.log(Level.WARNING, String.format("%s reading %s: %s is not numeric", ex.getClass().getName(), file, key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Material readConfig(HashMap<String, String> config, Gate gate, File file, String key, Material def) {
|
|
||||||
if (config.containsKey(key)) {
|
|
||||||
Material mat = Material.getMaterial(config.get(key));
|
|
||||||
if(mat != null) {
|
|
||||||
return mat;
|
|
||||||
}
|
|
||||||
Stargate.log.log(Level.WARNING, String.format("Error reading %s: %s is not a material", file, key));
|
|
||||||
}
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadGates(String gateFolder) {
|
|
||||||
File dir = new File(gateFolder);
|
|
||||||
File[] files;
|
|
||||||
|
|
||||||
if (dir.exists()) {
|
|
||||||
files = dir.listFiles(new StargateFilenameFilter());
|
|
||||||
} else {
|
|
||||||
files = new File[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (files == null || files.length == 0) {
|
|
||||||
if (dir.mkdir()) {
|
|
||||||
populateDefaults(gateFolder);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (File file : files) {
|
|
||||||
Gate gate = loadGate(file);
|
|
||||||
if (gate != null) registerGate(gate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void populateDefaults(String gateFolder) {
|
|
||||||
Character[][] layout = new Character[][] {
|
|
||||||
{' ', 'X','X', ' '},
|
|
||||||
{'X', '.', '.', 'X'},
|
|
||||||
{'-', '.', '.', '-'},
|
|
||||||
{'X', '*', '.', 'X'},
|
|
||||||
{' ', 'X', 'X', ' '},
|
|
||||||
};
|
|
||||||
HashMap<Character, Material> types = new HashMap<>();
|
|
||||||
types.put(ENTRANCE, Material.AIR);
|
|
||||||
types.put(EXIT, Material.AIR);
|
|
||||||
types.put(ANYTHING, Material.AIR);
|
|
||||||
types.put('X', Material.OBSIDIAN);
|
|
||||||
types.put('-', Material.OBSIDIAN);
|
|
||||||
|
|
||||||
Gate gate = new Gate("nethergate.gate", layout, types);
|
|
||||||
gate.save(gateFolder);
|
|
||||||
registerGate(gate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gate[] getGatesByControlBlock(Block block) {
|
|
||||||
return getGatesByControlBlock(block.getType());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gate[] getGatesByControlBlock(Material type) {
|
|
||||||
Gate[] result = new Gate[0];
|
|
||||||
ArrayList<Gate> lookup = controlBlocks.get(type);
|
|
||||||
|
|
||||||
if (lookup != null) result = lookup.toArray(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Gate getGateByName(String name) {
|
|
||||||
return gates.get(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getGateCount() {
|
|
||||||
return gates.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isGateBlock(Material type) {
|
|
||||||
return frameBlocks.contains(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class StargateFilenameFilter implements FilenameFilter {
|
|
||||||
public boolean accept(File dir, String name) {
|
|
||||||
return name.endsWith(".gate");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void clearGates() {
|
|
||||||
gates.clear();
|
|
||||||
controlBlocks.clear();
|
|
||||||
frameBlocks.clear();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,226 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LangLoader {
|
|
||||||
private final String UTF8_BOM = "\uFEFF";
|
|
||||||
// Variables
|
|
||||||
private final String datFolder;
|
|
||||||
private String lang;
|
|
||||||
private HashMap<String, String> strList;
|
|
||||||
private final HashMap<String, String> defList;
|
|
||||||
|
|
||||||
public LangLoader(String datFolder, String lang) {
|
|
||||||
this.lang = lang;
|
|
||||||
this.datFolder = datFolder;
|
|
||||||
|
|
||||||
File tmp = new File(datFolder, lang + ".txt");
|
|
||||||
if (!tmp.exists()) {
|
|
||||||
tmp.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
updateLanguage(lang);
|
|
||||||
|
|
||||||
strList = load(lang);
|
|
||||||
// We have a default hashMap used for when new text is added.
|
|
||||||
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
|
|
||||||
if (is != null) {
|
|
||||||
defList = load("en", is);
|
|
||||||
} else {
|
|
||||||
defList = null;
|
|
||||||
Stargate.log.severe("[Stargate] Error loading backup language. There may be missing text ingame");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean reload() {
|
|
||||||
// This extracts/updates the language as needed
|
|
||||||
updateLanguage(lang);
|
|
||||||
strList = load(lang);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getString(String name) {
|
|
||||||
String val = strList.get(name);
|
|
||||||
if (val == null && defList != null) val = defList.get(name);
|
|
||||||
if (val == null) return "";
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLang(String lang) {
|
|
||||||
this.lang = lang;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function updates on-disk language files
|
|
||||||
// with missing lines from the in-JAR files
|
|
||||||
private void updateLanguage(String lang) {
|
|
||||||
// Load the current language file
|
|
||||||
ArrayList<String> keyList = new ArrayList<>();
|
|
||||||
ArrayList<String> valList = new ArrayList<>();
|
|
||||||
|
|
||||||
HashMap<String, String> curLang = load(lang);
|
|
||||||
|
|
||||||
InputStream is = Stargate.class.getResourceAsStream("resources/" + lang + ".txt");
|
|
||||||
if (is == null) return;
|
|
||||||
|
|
||||||
boolean updated = false;
|
|
||||||
FileOutputStream fos = null;
|
|
||||||
try {
|
|
||||||
// Input stuff
|
|
||||||
InputStreamReader isr = new InputStreamReader(is);
|
|
||||||
BufferedReader br = new BufferedReader(isr);
|
|
||||||
|
|
||||||
String line = br.readLine();
|
|
||||||
boolean firstLine = true;
|
|
||||||
while (line != null) {
|
|
||||||
// Strip UTF BOM
|
|
||||||
if (firstLine) line = removeUTF8BOM(line);
|
|
||||||
firstLine = false;
|
|
||||||
// Split at first "="
|
|
||||||
int eq = line.indexOf('=');
|
|
||||||
if (eq == -1) {
|
|
||||||
keyList.add("");
|
|
||||||
valList.add("");
|
|
||||||
line = br.readLine();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String key = line.substring(0, eq);
|
|
||||||
String val = line.substring(eq);
|
|
||||||
|
|
||||||
if (curLang == null || curLang.get(key) == null) {
|
|
||||||
keyList.add(key);
|
|
||||||
valList.add(val);
|
|
||||||
updated = true;
|
|
||||||
} else {
|
|
||||||
keyList.add(key);
|
|
||||||
valList.add("=" + curLang.get(key).replace('\u00A7', '&'));
|
|
||||||
curLang.remove(key);
|
|
||||||
}
|
|
||||||
line = br.readLine();
|
|
||||||
}
|
|
||||||
br.close();
|
|
||||||
|
|
||||||
// Save file
|
|
||||||
fos = new FileOutputStream(datFolder + lang + ".txt");
|
|
||||||
OutputStreamWriter out = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
|
|
||||||
BufferedWriter bw = new BufferedWriter(out);
|
|
||||||
|
|
||||||
// Output normal Language data
|
|
||||||
for (int i = 0; i < keyList.size(); i++) {
|
|
||||||
bw.write(keyList.get(i) + valList.get(i));
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
bw.newLine();
|
|
||||||
// Output any custom language strings the user had
|
|
||||||
if(curLang != null) {
|
|
||||||
for (String key : curLang.keySet()) {
|
|
||||||
bw.write(key + "=" + curLang.get(key));
|
|
||||||
bw.newLine();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bw.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (fos != null) {
|
|
||||||
try {fos.close();} catch (Exception ex) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (updated)
|
|
||||||
Stargate.log.info("[Stargate] Your language file (" + lang + ".txt) has been updated");
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, String> load(String lang) {
|
|
||||||
return load(lang, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private HashMap<String, String> load(String lang, InputStream is) {
|
|
||||||
HashMap<String, String> strings = new HashMap<>();
|
|
||||||
FileInputStream fis = null;
|
|
||||||
InputStreamReader isr = null;
|
|
||||||
try {
|
|
||||||
if (is == null) {
|
|
||||||
fis = new FileInputStream(datFolder + lang + ".txt");
|
|
||||||
isr = new InputStreamReader(fis, StandardCharsets.UTF_8);
|
|
||||||
} else {
|
|
||||||
isr = new InputStreamReader(is, StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
BufferedReader br = new BufferedReader(isr);
|
|
||||||
String line = br.readLine();
|
|
||||||
boolean firstLine = true;
|
|
||||||
while (line != null) {
|
|
||||||
// Strip UTF BOM
|
|
||||||
if (firstLine) line = removeUTF8BOM(line);
|
|
||||||
firstLine = false;
|
|
||||||
// Split at first "="
|
|
||||||
int eq = line.indexOf('=');
|
|
||||||
if (eq == -1) {
|
|
||||||
line = br.readLine();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String key = line.substring(0, eq);
|
|
||||||
String val = ChatColor.translateAlternateColorCodes('&', line.substring(eq + 1));
|
|
||||||
strings.put(key, val);
|
|
||||||
line = br.readLine();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
if (fis != null) {
|
|
||||||
try {
|
|
||||||
fis.close();
|
|
||||||
} catch (Exception ex) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return strings;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void debug() {
|
|
||||||
Set<String> keys = strList.keySet();
|
|
||||||
for (String key : keys) {
|
|
||||||
Stargate.debug("LangLoader::Debug::strList", key + " => " + strList.get(key));
|
|
||||||
}
|
|
||||||
if (defList == null) return;
|
|
||||||
keys = defList.keySet();
|
|
||||||
for (String key : keys) {
|
|
||||||
Stargate.debug("LangLoader::Debug::defList", key + " => " + defList.get(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String removeUTF8BOM(String s) {
|
|
||||||
if (s.startsWith(UTF8_BOM)) {
|
|
||||||
s = s.substring(1);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,69 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class StargateActivateEvent extends StargateEvent {
|
|
||||||
private final Player player;
|
|
||||||
private ArrayList<String> destinations;
|
|
||||||
private String destination;
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
public StargateActivateEvent(Portal portal, Player player, ArrayList<String> destinations, String destination) {
|
|
||||||
super("StargatActivateEvent", portal);
|
|
||||||
|
|
||||||
this.player = player;
|
|
||||||
this.destinations = destinations;
|
|
||||||
this.destination = destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getDestinations() {
|
|
||||||
return destinations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDestinations(ArrayList<String> destinations) {
|
|
||||||
this.destinations = destinations;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDestination() {
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDestination(String destination) {
|
|
||||||
this.destination = destination;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class StargateCreateEvent extends StargateEvent {
|
|
||||||
private final Player player;
|
|
||||||
private boolean deny;
|
|
||||||
private String denyReason;
|
|
||||||
private final String[] lines;
|
|
||||||
private int cost;
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StargateCreateEvent(Player player, Portal portal, String[] lines, boolean deny, String denyReason, int cost) {
|
|
||||||
super("StargateCreateEvent", portal);
|
|
||||||
this.player = player;
|
|
||||||
this.lines = lines;
|
|
||||||
this.deny = deny;
|
|
||||||
this.denyReason = denyReason;
|
|
||||||
this.cost = cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
|
||||||
return lines[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getDeny() {
|
|
||||||
return deny;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeny(boolean deny) {
|
|
||||||
this.deny = deny;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDenyReason() {
|
|
||||||
return denyReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDenyReason(String denyReason) {
|
|
||||||
this.denyReason = denyReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCost() {
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCost(int cost) {
|
|
||||||
this.cost = cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,77 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class StargateDestroyEvent extends StargateEvent {
|
|
||||||
private final Player player;
|
|
||||||
private boolean deny;
|
|
||||||
private String denyReason;
|
|
||||||
private int cost;
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StargateDestroyEvent(Portal portal, Player player, boolean deny, String denyMsg, int cost) {
|
|
||||||
super("StargateDestroyEvent", portal);
|
|
||||||
this.player = player;
|
|
||||||
this.deny = deny;
|
|
||||||
this.denyReason = denyMsg;
|
|
||||||
this.cost = cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getDeny() {
|
|
||||||
return deny;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeny(boolean deny) {
|
|
||||||
this.deny = deny;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDenyReason() {
|
|
||||||
return denyReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDenyReason(String denyReason) {
|
|
||||||
this.denyReason = denyReason;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCost() {
|
|
||||||
return cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCost(int cost) {
|
|
||||||
this.cost = cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class StargateOpenEvent extends StargateEvent {
|
|
||||||
private final Player player;
|
|
||||||
private boolean force;
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
public StargateOpenEvent(Player player, Portal portal, boolean force) {
|
|
||||||
super ("StargateOpenEvent", portal);
|
|
||||||
|
|
||||||
this.player = player;
|
|
||||||
this.force = force;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the player than opened the gate.
|
|
||||||
* @return player than opened the gate
|
|
||||||
*/
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getForce() {
|
|
||||||
return force;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setForce(boolean force) {
|
|
||||||
this.force = force;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate.event;
|
|
||||||
|
|
||||||
import net.TheDgtl.Stargate.Portal;
|
|
||||||
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stargate - A portal plugin for Bukkit
|
|
||||||
* Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class StargatePortalEvent extends StargateEvent {
|
|
||||||
private final Player player;
|
|
||||||
private final Portal destination;
|
|
||||||
private Location exit;
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public StargatePortalEvent(Player player, Portal portal, Portal dest, Location exit) {
|
|
||||||
super ("StargatePortalEvent", portal);
|
|
||||||
|
|
||||||
this.player = player;
|
|
||||||
this.destination = dest;
|
|
||||||
this.exit = exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the player that went through the gate.
|
|
||||||
* @return player that went through the gate
|
|
||||||
*/
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the destination gate
|
|
||||||
* @return destination gate
|
|
||||||
*/
|
|
||||||
public Portal getDestination() {
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the location of the players exit point
|
|
||||||
* @return org.bukkit.Location Location of the exit point
|
|
||||||
*/
|
|
||||||
public Location getExit() {
|
|
||||||
return exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the location of the players exit point
|
|
||||||
*/
|
|
||||||
public void setExit(Location loc) {
|
|
||||||
this.exit = loc;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,57 +0,0 @@
|
|||||||
package net.TheDgtl.Stargate;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
|
|
||||||
public class pmListener implements PluginMessageListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPluginMessageReceived(String channel, Player unused, byte[] message) {
|
|
||||||
if (!Stargate.enableBungee || !channel.equals("BungeeCord")) return;
|
|
||||||
|
|
||||||
// Get data from message
|
|
||||||
String inChannel;
|
|
||||||
byte[] data;
|
|
||||||
try {
|
|
||||||
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
|
|
||||||
inChannel = in.readUTF();
|
|
||||||
short len = in.readShort();
|
|
||||||
data = new byte[len];
|
|
||||||
in.readFully(data);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Stargate.log.severe("[Stargate] Error receiving BungeeCord message");
|
|
||||||
ex.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify that it's an SGBungee packet
|
|
||||||
if (!inChannel.equals("SGBungee")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Data should be player name, and destination gate name
|
|
||||||
String msg = new String(data);
|
|
||||||
String[] parts = msg.split("#@#");
|
|
||||||
|
|
||||||
String playerName = parts[0];
|
|
||||||
String destination = parts[1];
|
|
||||||
|
|
||||||
// Check if the player is online, if so, teleport, otherwise, queue
|
|
||||||
Player player = Stargate.server.getPlayer(playerName);
|
|
||||||
if (player == null) {
|
|
||||||
Stargate.bungeeQueue.put(playerName.toLowerCase(), destination);
|
|
||||||
} else {
|
|
||||||
Portal dest = Portal.getBungeeGate(destination);
|
|
||||||
// Specified an invalid gate. For now we'll just let them connect at their current location
|
|
||||||
if (dest == null) {
|
|
||||||
Stargate.log.info("[Stargate] Bungee gate " + destination + " does not exist");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dest.teleport(player, dest, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user