-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
230 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/marco/simplecivilisations/commands/ReviveCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.marco.simplecivilisations.commands; | ||
|
||
import com.marco.simplecivilisations.SimpleCivilisations; | ||
import com.marco.simplecivilisations.sql.User; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.command.Command; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.command.TabExecutor; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class ReviveCommand implements TabExecutor { | ||
private final SimpleCivilisations plugin; | ||
public ReviveCommand(SimpleCivilisations plugin) { | ||
this.plugin = plugin; | ||
} | ||
@Override | ||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { | ||
if (args.length == 0) { | ||
sender.sendMessage(ChatColor.RED + "Missing argument."); | ||
return true; | ||
} | ||
|
||
UUID uuid = SimpleCivilisations.uuidFromName(args[0]); | ||
if (uuid == null) { | ||
sender.sendMessage(ChatColor.RED + "No player found."); | ||
return true; | ||
} | ||
|
||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { | ||
User user = plugin.getSQL().getUser(uuid); | ||
if (user == null) { | ||
sender.sendMessage(ChatColor.RED + "No user found."); | ||
return; | ||
} | ||
user.setLastDeath(null); | ||
sender.sendMessage("Done."); | ||
}); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/marco/simplecivilisations/listeners/EventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.marco.simplecivilisations.listeners; | ||
|
||
import com.marco.simplecivilisations.SimpleCivilisations; | ||
import org.bukkit.event.Listener; | ||
|
||
public abstract class EventListener implements Listener { | ||
protected final SimpleCivilisations plugin; | ||
|
||
public EventListener(SimpleCivilisations plugin) { | ||
this.plugin = plugin; | ||
} | ||
} |
24 changes: 19 additions & 5 deletions
24
src/main/java/com/marco/simplecivilisations/listeners/PlayerJoinListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
package com.marco.simplecivilisations.listeners; | ||
|
||
import com.marco.simplecivilisations.SimpleCivilisations; | ||
import com.marco.simplecivilisations.commands.SeenCommand; | ||
import com.marco.simplecivilisations.sql.User; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
public class PlayerJoinListener implements Listener { | ||
private final SimpleCivilisations plugin; | ||
import java.sql.Timestamp; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class PlayerJoinListener extends EventListener { | ||
public PlayerJoinListener(SimpleCivilisations plugin) { | ||
this.plugin = plugin; | ||
super(plugin); | ||
} | ||
|
||
@EventHandler | ||
public void listen(PlayerJoinEvent event) { | ||
plugin.getSQL().createUser(event.getPlayer()); | ||
User user = plugin.getSQL().createUser(event.getPlayer()); | ||
if (user.getLastDeath() == null) return; | ||
// TODO: get deathban duration from config. | ||
int minutes = 15; | ||
Duration duration = Duration.between(user.getLastDeath().toInstant(), Instant.now()); | ||
if (duration.toMinutes() > minutes) { | ||
user.setLastDeath(null); | ||
} else { | ||
Timestamp timeWhenNotBanned = Timestamp.from(user.getLastDeath().toInstant().plusSeconds(TimeUnit.MINUTES.toSeconds(minutes))); | ||
event.getPlayer().kickPlayer("You are deathbanned for another " + SeenCommand.getTimestampDifference(Timestamp.from(Instant.now()), timeWhenNotBanned) + "."); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/marco/simplecivilisations/listeners/PlayerKickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.marco.simplecivilisations.listeners; | ||
|
||
import com.marco.simplecivilisations.SimpleCivilisations; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.player.PlayerKickEvent; | ||
|
||
public class PlayerKickListener extends EventListener { | ||
|
||
public PlayerKickListener(SimpleCivilisations plugin) { | ||
super(plugin); | ||
} | ||
|
||
@EventHandler | ||
public void listen(PlayerKickEvent event) { | ||
plugin.getSQL().updateSession(event.getPlayer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/marco/simplecivilisations/listeners/PlayerRespawnEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.marco.simplecivilisations.listeners; | ||
|
||
import com.marco.simplecivilisations.SimpleCivilisations; | ||
import com.marco.simplecivilisations.sql.User; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Location; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.Instant; | ||
|
||
public class PlayerRespawnEvent extends EventListener { | ||
public PlayerRespawnEvent(SimpleCivilisations plugin) { | ||
super(plugin); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.MONITOR) | ||
public void listen(org.bukkit.event.player.PlayerRespawnEvent event) { | ||
User user = plugin.getSQL().getUser(event.getPlayer().getUniqueId()); | ||
user.setLastDeath(Timestamp.from(Instant.now())); | ||
Location bed = event.getPlayer().getBedSpawnLocation(); | ||
event.setRespawnLocation(bed != null ? bed : user.getSpawnPoint()); | ||
Bukkit.getScheduler().runTask(plugin, () -> { | ||
event.getPlayer().kickPlayer("You died."); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.